diff options
-rw-r--r-- | heatclient/osc/v1/event.py | 27 | ||||
-rw-r--r-- | heatclient/osc/v1/resource.py | 2 | ||||
-rw-r--r-- | heatclient/tests/unit/osc/fakes.py | 194 | ||||
-rw-r--r-- | heatclient/tests/unit/osc/utils.py | 7 | ||||
-rw-r--r-- | heatclient/tests/unit/osc/v1/fakes.py | 24 | ||||
-rw-r--r-- | heatclient/tests/unit/osc/v1/test_event.py | 30 | ||||
-rw-r--r-- | heatclient/tests/unit/osc/v1/test_resource.py | 17 | ||||
-rw-r--r-- | heatclient/tests/unit/osc/v1/test_resource_type.py | 18 | ||||
-rw-r--r-- | heatclient/tests/unit/osc/v1/test_service.py | 5 | ||||
-rw-r--r-- | heatclient/tests/unit/osc/v1/test_snapshot.py | 26 | ||||
-rw-r--r-- | heatclient/tests/unit/osc/v1/test_software_config.py | 21 | ||||
-rw-r--r-- | heatclient/tests/unit/osc/v1/test_software_deployment.py | 46 | ||||
-rw-r--r-- | heatclient/tests/unit/osc/v1/test_stack.py | 111 | ||||
-rw-r--r-- | heatclient/tests/unit/osc/v1/test_template.py | 4 | ||||
-rw-r--r-- | heatclient/v1/shell.py | 2 | ||||
-rw-r--r-- | setup.cfg | 8 | ||||
-rw-r--r-- | test-requirements.txt | 4 |
17 files changed, 144 insertions, 402 deletions
diff --git a/heatclient/osc/v1/event.py b/heatclient/osc/v1/event.py index feee81d..233b3ed 100644 --- a/heatclient/osc/v1/event.py +++ b/heatclient/osc/v1/event.py @@ -15,6 +15,7 @@ import logging import time +from cliff.formatters import base from cliff import lister from cliff import show from openstackclient.common import utils @@ -88,7 +89,11 @@ class ListEvent(lister.Lister): @property def formatter_default(self): - return 'value' + return 'log' + + @property + def formatter_namespace(self): + return 'heatclient.event.formatter.list' def get_parser(self, prog_name): parser = super(ListEvent, self).get_parser(prog_name) @@ -173,8 +178,8 @@ class ListEvent(lister.Lister): nested_depth = 0 if parsed_args.follow: - if parsed_args.formatter != 'value': - msg = _('--follow can only be specified with --format value') + if parsed_args.formatter != 'log': + msg = _('--follow can only be specified with --format log') raise exc.CommandError(msg) marker = parsed_args.marker @@ -205,9 +210,8 @@ class ListEvent(lister.Lister): if parsed_args.sort: events = utils.sort_items(events, ','.join(parsed_args.sort)) - if parsed_args.formatter == 'value': - events = heat_utils.event_log_formatter(events).split('\n') - return [], [e.split(' ') for e in events] + if parsed_args.formatter == 'log': + return [], events if len(events): if hasattr(events[0], 'resource_name'): @@ -220,3 +224,14 @@ class ListEvent(lister.Lister): columns, (utils.get_item_properties(s, columns) for s in events) ) + + +class LogFormatter(base.ListFormatter): + """A formatter which prints event objects in a log style""" + + def add_argument_group(self, parser): + pass + + def emit_list(self, column_names, data, stdout, parsed_args): + stdout.write(heat_utils.event_log_formatter(data)) + stdout.write('\n') diff --git a/heatclient/osc/v1/resource.py b/heatclient/osc/v1/resource.py index 7f9d1b2..056fbb1 100644 --- a/heatclient/osc/v1/resource.py +++ b/heatclient/osc/v1/resource.py @@ -104,7 +104,7 @@ class ResourceList(lister.Lister): action='append', help=_('Filter parameters to apply on returned resources based on ' 'their name, status, type, action, id and ' - 'physcial_resource_id') + 'physical_resource_id') ) return parser diff --git a/heatclient/tests/unit/osc/fakes.py b/heatclient/tests/unit/osc/fakes.py index 8ce67c7..ba624ad 100644 --- a/heatclient/tests/unit/osc/fakes.py +++ b/heatclient/tests/unit/osc/fakes.py @@ -14,153 +14,11 @@ # import json -import sys -from oslo_utils import reflection import requests import six -AUTH_TOKEN = "foobar" -AUTH_URL = "http://0.0.0.0" -USERNAME = "itchy" -PASSWORD = "scratchy" -TEST_RESPONSE_DICT = { - "access": { - "metadata": { - "is_admin": 0, - "roles": [ - "1234", - ] - }, - "serviceCatalog": [ - { - "endpoints": [ - { - "adminURL": AUTH_URL + "/v2.0", - "id": "1234", - "internalURL": AUTH_URL + "/v2.0", - "publicURL": AUTH_URL + "/v2.0", - "region": "RegionOne" - } - ], - "endpoints_links": [], - "name": "keystone", - "type": "identity" - } - ], - "token": { - "expires": "2035-01-01T00:00:01Z", - "id": AUTH_TOKEN, - "issued_at": "2013-01-01T00:00:01.692048", - "tenant": { - "description": None, - "enabled": True, - "id": "1234", - "name": "testtenant" - } - }, - "user": { - "id": "5678", - "name": USERNAME, - "roles": [ - { - "name": "testrole" - }, - ], - "roles_links": [], - "username": USERNAME - } - } -} -TEST_RESPONSE_DICT_V3 = { - "token": { - "audit_ids": [ - "a" - ], - "catalog": [ - ], - "expires_at": "2034-09-29T18:27:15.978064Z", - "extras": {}, - "issued_at": "2014-09-29T17:27:15.978097Z", - "methods": [ - "password" - ], - "project": { - "domain": { - "id": "default", - "name": "Default" - }, - "id": "bbb", - "name": "project" - }, - "roles": [ - ], - "user": { - "domain": { - "id": "default", - "name": "Default" - }, - "id": "aaa", - "name": USERNAME - } - } -} -TEST_VERSIONS = { - "versions": { - "values": [ - { - "id": "v3.0", - "links": [ - { - "href": AUTH_URL, - "rel": "self" - } - ], - "media-types": [ - { - "base": "application/json", - "type": "application/vnd.openstack.identity-v3+json" - }, - { - "base": "application/xml", - "type": "application/vnd.openstack.identity-v3+xml" - } - ], - "status": "stable", - "updated": "2013-03-06T00:00:00Z" - }, - { - "id": "v2.0", - "links": [ - { - "href": AUTH_URL, - "rel": "self" - }, - { - "href": "http://docs.openstack.org/", - "rel": "describedby", - "type": "text/html" - } - ], - "media-types": [ - { - "base": "application/json", - "type": "application/vnd.openstack.identity-v2.0+json" - }, - { - "base": "application/xml", - "type": "application/vnd.openstack.identity-v2.0+xml" - } - ], - "status": "stable", - "updated": "2014-04-17T00:00:00Z" - } - ] - } -} - - class FakeStdout(object): def __init__(self): self.content = [] @@ -175,58 +33,6 @@ class FakeStdout(object): return result -class FakeApp(object): - def __init__(self, _stdout): - self.stdout = _stdout - self.client_manager = None - self.stdin = sys.stdin - self.stdout = _stdout or sys.stdout - self.stderr = sys.stderr - - -class FakeClient(object): - def __init__(self, **kwargs): - self.endpoint = kwargs['endpoint'] - self.token = kwargs['token'] - - -class FakeClientManager(object): - def __init__(self): - self.compute = None - self.identity = None - self.image = None - self.object_store = None - self.volume = None - self.network = None - self.session = None - self.auth_ref = None - - -class FakeModule(object): - def __init__(self, name, version): - self.name = name - self.__version__ = version - - -class FakeResource(object): - def __init__(self, manager, info, loaded=False): - self.manager = manager - self._info = info - self._add_details(info) - self._loaded = loaded - - def _add_details(self, info): - for (k, v) in six.iteritems(info): - setattr(self, k, v) - - def __repr__(self): - reprkeys = sorted(k for k in self.__dict__.keys() if k[0] != '_' and - k != 'manager') - info = ", ".join("%s=%s" % (k, getattr(self, k)) for k in reprkeys) - class_name = reflection.get_class_name(self, fully_qualified=False) - return "<%s %s>" % (class_name, info) - - class FakeResponse(requests.Response): def __init__(self, headers={}, status_code=200, data=None, encoding=None): super(FakeResponse, self).__init__() diff --git a/heatclient/tests/unit/osc/utils.py b/heatclient/tests/unit/osc/utils.py index be0ca81..a3e5aaf 100644 --- a/heatclient/tests/unit/osc/utils.py +++ b/heatclient/tests/unit/osc/utils.py @@ -17,6 +17,7 @@ import os import fixtures +import mock import sys import testtools @@ -76,8 +77,10 @@ class TestCommand(TestCase): super(TestCommand, self).setUp() # Build up a fake app self.fake_stdout = fakes.FakeStdout() - self.app = fakes.FakeApp(self.fake_stdout) - self.app.client_manager = fakes.FakeClientManager() + self.app = mock.MagicMock() + self.app.stdout = self.fake_stdout + self.app.stdin = sys.stdin + self.app.stderr = sys.stderr def check_parser(self, cmd, args, verify_args): cmd_parser = cmd.get_parser('check_parser') diff --git a/heatclient/tests/unit/osc/v1/fakes.py b/heatclient/tests/unit/osc/v1/fakes.py index 89df035..87525bb 100644 --- a/heatclient/tests/unit/osc/v1/fakes.py +++ b/heatclient/tests/unit/osc/v1/fakes.py @@ -15,33 +15,11 @@ import mock -from heatclient.tests.unit.osc import fakes from heatclient.tests.unit.osc import utils -class FakeOrchestrationv1Client(object): - def __init__(self, **kwargs): - self.http_client = mock.Mock() - self.http_client.auth_token = kwargs['token'] - self.http_client.management_url = kwargs['endpoint'] - self.stacks = mock.Mock() - self.stacks.list = mock.Mock(return_value=[]) - self.resources = fakes.FakeResource(None, {}) - self.resource_types = fakes.FakeResource(None, {}) - self.events = fakes.FakeResource(None, {}) - self.actions = fakes.FakeResource(None, {}) - self.build_info = fakes.FakeResource(None, {}) - self.services = fakes.FakeResource(None, {}) - self.software_deployments = fakes.FakeResource(None, {}) - self.software_configs = fakes.FakeResource(None, {}) - self.template_versions = fakes.FakeResource(None, {}) - - class TestOrchestrationv1(utils.TestCommand): def setUp(self): super(TestOrchestrationv1, self).setUp() - self.app.client_manager.orchestration = FakeOrchestrationv1Client( - endpoint=fakes.AUTH_URL, - token=fakes.AUTH_TOKEN, - ) + self.app.client_manager.orchestration = mock.MagicMock() diff --git a/heatclient/tests/unit/osc/v1/test_event.py b/heatclient/tests/unit/osc/v1/test_event.py index 668a62e..31896bb 100644 --- a/heatclient/tests/unit/osc/v1/test_event.py +++ b/heatclient/tests/unit/osc/v1/test_event.py @@ -61,10 +61,7 @@ class TestEventShow(TestEvent): def test_event_show(self): arglist = ['--format', self.format, 'my_stack', 'my_resource', '1234'] parsed_args = self.check_parser(self.cmd, arglist, []) - self.stack_client.get = mock.MagicMock() - self.resource_client.get = mock.MagicMock() - self.event_client.get = mock.MagicMock( - return_value=events.Event(None, self.response)) + self.event_client.get.return_value = events.Event(None, self.response) self.cmd.take_action(parsed_args) @@ -83,23 +80,17 @@ class TestEventShow(TestEvent): def test_event_show_stack_not_found(self): error = 'Stack not found' - self.stack_client.get = mock.MagicMock( - side_effect=exc.HTTPNotFound(error)) + self.stack_client.get.side_effect = exc.HTTPNotFound(error) self._test_not_found(error) def test_event_show_resource_not_found(self): error = 'Resource not found' - self.stack_client.get = mock.MagicMock() - self.resource_client.get = mock.MagicMock( - side_effect=exc.HTTPNotFound(error)) + self.stack_client.get.side_effect = exc.HTTPNotFound(error) self._test_not_found(error) def test_event_show_event_not_found(self): error = 'Event not found' - self.stack_client.get = mock.MagicMock() - self.resource_client.get = mock.MagicMock() - self.event_client.get = mock.MagicMock( - side_effect=exc.HTTPNotFound(error)) + self.stack_client.get.side_effect = exc.HTTPNotFound(error) self._test_not_found(error) @@ -142,8 +133,8 @@ class TestEventList(TestEvent): super(TestEventList, self).setUp() self.cmd = event.ListEvent(self.app, None) self.event = self.MockEvent() - self.event_client.list = mock.MagicMock(return_value=[self.event]) - self.resource_client.list = mock.MagicMock(return_value={}) + self.event_client.list.return_value = [self.event] + self.resource_client.list.return_value = {} def test_event_list_defaults(self): arglist = ['my_stack', '--format', 'table'] @@ -225,14 +216,13 @@ class TestEventList(TestEvent): self.assertEqual([], data) self.assertEqual(expected, self.fake_stdout.make_string()) - def test_event_list_value_format(self): + def test_event_list_log_format(self): arglist = ['my_stack'] expected = ('2015-11-13 10:02:17 [resource1]: CREATE_COMPLETE ' - 'state changed') + 'state changed\n') parsed_args = self.check_parser(self.cmd, arglist, []) - columns, data = self.cmd.take_action(parsed_args) + self.cmd.run(parsed_args) self.event_client.list.assert_called_with(**self.defaults) - self.assertEqual([], columns) - self.assertEqual([expected.split(' ')], data) + self.assertEqual(expected, self.fake_stdout.make_string()) diff --git a/heatclient/tests/unit/osc/v1/test_resource.py b/heatclient/tests/unit/osc/v1/test_resource.py index 337d284..5193cb8 100644 --- a/heatclient/tests/unit/osc/v1/test_resource.py +++ b/heatclient/tests/unit/osc/v1/test_resource.py @@ -51,8 +51,8 @@ class TestStackResourceShow(TestResource): def setUp(self): super(TestStackResourceShow, self).setUp() self.cmd = resource.ResourceShow(self.app, None) - self.resource_client.get = mock.MagicMock( - return_value=v1_resources.Resource(None, self.response)) + self.resource_client.get.return_value = v1_resources.Resource( + None, self.response) def test_resource_show(self): arglist = ['my_stack', 'my_resource'] @@ -119,8 +119,8 @@ class TestStackResourceList(TestResource): def setUp(self): super(TestStackResourceList, self).setUp() self.cmd = resource.ResourceList(self.app, None) - self.resource_client.list = mock.MagicMock( - return_value=[v1_resources.Resource(None, self.response)]) + self.resource_client.list.return_value = [ + v1_resources.Resource(None, self.response)] def test_resource_list(self): arglist = ['my_stack'] @@ -220,7 +220,7 @@ class TestResourceMetadata(TestResource): def setUp(self): super(TestResourceMetadata, self).setUp() self.cmd = resource.ResourceMetadata(self.app, None) - self.resource_client.metadata = mock.Mock(return_value={}) + self.resource_client.metadata.return_value = {} def test_resource_metadata(self): arglist = ['my_stack', 'my_resource'] @@ -243,8 +243,7 @@ class TestResourceMetadata(TestResource): def test_resource_metadata_error(self): arglist = ['my_stack', 'my_resource'] parsed_args = self.check_parser(self.cmd, arglist, []) - self.resource_client.metadata = mock.Mock( - side_effect=heat_exc.HTTPNotFound) + self.resource_client.metadata.side_effect = heat_exc.HTTPNotFound error = self.assertRaises(exc.CommandError, self.cmd.take_action, parsed_args) @@ -257,7 +256,6 @@ class TestResourceSignal(TestResource): def setUp(self): super(TestResourceSignal, self).setUp() self.cmd = resource.ResourceSignal(self.app, None) - self.resource_client.signal = mock.Mock() def test_resource_signal(self): arglist = ['my_stack', 'my_resource'] @@ -271,8 +269,7 @@ class TestResourceSignal(TestResource): def test_resource_signal_error(self): arglist = ['my_stack', 'my_resource'] parsed_args = self.check_parser(self.cmd, arglist, []) - self.resource_client.signal = mock.Mock( - side_effect=heat_exc.HTTPNotFound) + self.resource_client.signal.side_effect = heat_exc.HTTPNotFound error = self.assertRaises(exc.CommandError, self.cmd.take_action, parsed_args) diff --git a/heatclient/tests/unit/osc/v1/test_resource_type.py b/heatclient/tests/unit/osc/v1/test_resource_type.py index 06b8913..738915d 100644 --- a/heatclient/tests/unit/osc/v1/test_resource_type.py +++ b/heatclient/tests/unit/osc/v1/test_resource_type.py @@ -11,8 +11,6 @@ # under the License. # -import mock - from openstackclient.common import exceptions as exc from heatclient import exc as heat_exc @@ -32,10 +30,8 @@ class TestResourceTypeShow(TestResourceType): def setUp(self): super(TestResourceTypeShow, self).setUp() self.cmd = resource_type.ResourceTypeShow(self.app, None) - self.mock_client.resource_types.get = mock.Mock( - return_value={}) - self.mock_client.resource_types.generate_template = mock.Mock( - return_value={}) + self.mock_client.resource_types.get.return_value = {} + self.mock_client.resource_types.generate_template.return_value = {} def test_resourcetype_show(self): arglist = ['OS::Heat::None'] @@ -55,16 +51,15 @@ class TestResourceTypeShow(TestResourceType): def test_resourcetype_show_error_get(self): arglist = ['OS::Heat::None'] parsed_args = self.check_parser(self.cmd, arglist, []) - self.mock_client.resource_types.get = mock.Mock( - side_effect=heat_exc.HTTPNotFound) + self.mock_client.resource_types.get.side_effect = heat_exc.HTTPNotFound self.assertRaises(exc.CommandError, self.cmd.take_action, parsed_args) def test_resourcetype_show_error_template(self): arglist = ['OS::Heat::None', '--template-type', 'hot'] parsed_args = self.check_parser(self.cmd, arglist, []) - self.mock_client.resource_types.generate_template = mock.Mock( - side_effect=heat_exc.HTTPNotFound) + self.mock_client.resource_types.generate_template.side_effect = \ + heat_exc.HTTPNotFound self.assertRaises(exc.CommandError, self.cmd.take_action, parsed_args) def test_resourcetype_show_template_hot(self): @@ -137,8 +132,7 @@ class TestTypeList(TestResourceType): def setUp(self): super(TestTypeList, self).setUp() self.cmd = resource_type.ResourceTypeList(self.app, None) - self.mock_client.resource_types.list = mock.Mock( - return_value=self.list_response) + self.mock_client.resource_types.list.return_value = self.list_response def test_resourcetype_list(self): arglist = [] diff --git a/heatclient/tests/unit/osc/v1/test_service.py b/heatclient/tests/unit/osc/v1/test_service.py index 8128e85..7fe6443 100644 --- a/heatclient/tests/unit/osc/v1/test_service.py +++ b/heatclient/tests/unit/osc/v1/test_service.py @@ -11,8 +11,6 @@ # under the License. # -import mock - from heatclient.osc.v1 import service as osc_service from heatclient.tests.unit.osc.v1 import fakes as orchestration_fakes @@ -54,8 +52,7 @@ class TestServiceList(orchestration_fakes.TestOrchestrationv1): super(TestServiceList, self).setUp() self.cmd = osc_service.ListService(self.app, None) self.mock_client = self.app.client_manager.orchestration - self.mock_client.services.list = mock.Mock( - return_value=self.response) + self.mock_client.services.list.return_value = self.response def test_service_list(self): arglist = [] diff --git a/heatclient/tests/unit/osc/v1/test_snapshot.py b/heatclient/tests/unit/osc/v1/test_snapshot.py index f4e0550..47683bb 100644 --- a/heatclient/tests/unit/osc/v1/test_snapshot.py +++ b/heatclient/tests/unit/osc/v1/test_snapshot.py @@ -11,8 +11,6 @@ # under the License. # -import mock - from openstackclient.common import exceptions as exc from heatclient import exc as heat_exc @@ -31,9 +29,7 @@ class TestListSnapshot(TestStack): def setUp(self): super(TestListSnapshot, self).setUp() self.cmd = snapshot.ListSnapshot(self.app, None) - self.stack_client.snapshot_list = mock.Mock( - return_value={'snapshots': []} - ) + self.stack_client.snapshot_list.return_value = {'snapshots': []} def test_snapshot_list(self): arglist = ['my_stack'] @@ -62,8 +58,7 @@ class TestSnapshotShow(TestStack): def test_snapshot_show(self): arglist = ['my_stack', 'snapshot_id'] parsed_args = self.check_parser(self.cmd, arglist, []) - self.stack_client.snapshot_show = mock.Mock( - return_value={}) + self.stack_client.snapshot_show.return_value = {} self.cmd.take_action(parsed_args) self.stack_client.snapshot_show.assert_called_with( 'my_stack', 'snapshot_id') @@ -71,8 +66,7 @@ class TestSnapshotShow(TestStack): def test_snapshot_not_found(self): arglist = ['my_stack', 'snapshot_id'] parsed_args = self.check_parser(self.cmd, arglist, []) - self.stack_client.snapshot_show = mock.Mock( - side_effect=heat_exc.HTTPNotFound()) + self.stack_client.snapshot_show.side_effect = heat_exc.HTTPNotFound() self.assertRaises( exc.CommandError, self.cmd.take_action, @@ -83,7 +77,6 @@ class TestRestoreSnapshot(TestStack): def setUp(self): super(TestRestoreSnapshot, self).setUp() self.cmd = snapshot.RestoreSnapshot(self.app, None) - self.stack_client.restore = mock.Mock() def test_snapshot_restore(self): arglist = ['my_stack', 'my_snapshot'] @@ -121,8 +114,7 @@ class TestSnapshotCreate(TestStack): def test_snapshot_create(self): arglist = ['my_stack', '--name', 'test_snapshot'] parsed_args = self.check_parser(self.cmd, arglist, []) - self.stack_client.snapshot = mock.Mock( - return_value=self.get_response) + self.stack_client.snapshot.return_value = self.get_response self.cmd.take_action(parsed_args) self.stack_client.snapshot.assert_called_with( 'my_stack', 'test_snapshot') @@ -130,8 +122,7 @@ class TestSnapshotCreate(TestStack): def test_snapshot_create_no_name(self): arglist = ['my_stack'] parsed_args = self.check_parser(self.cmd, arglist, []) - self.stack_client.snapshot = mock.Mock( - return_value=self.get_response) + self.stack_client.snapshot.return_value = self.get_response self.cmd.take_action(parsed_args) self.stack_client.snapshot.assert_called_with( 'my_stack', None) @@ -139,8 +130,7 @@ class TestSnapshotCreate(TestStack): def test_snapshot_create_error(self): arglist = ['my_stack', '--name', 'test_snapshot'] parsed_args = self.check_parser(self.cmd, arglist, []) - self.stack_client.snapshot = mock.Mock( - side_effect=heat_exc.HTTPNotFound) + self.stack_client.snapshot.side_effect = heat_exc.HTTPNotFound self.assertRaises( exc.CommandError, self.cmd.take_action, @@ -155,7 +145,6 @@ class TestSnapshotDelete(TestStack): def test_snapshot_delete(self): arglist = ['my_stack', 'snapshot_id'] parsed_args = self.check_parser(self.cmd, arglist, []) - self.stack_client.snapshot_delete = mock.Mock() self.cmd.take_action(parsed_args) self.stack_client.snapshot_delete.assert_called_with( 'my_stack', 'snapshot_id') @@ -163,8 +152,7 @@ class TestSnapshotDelete(TestStack): def test_snapshot_delete_not_found(self): arglist = ['my_stack', 'snapshot_id'] parsed_args = self.check_parser(self.cmd, arglist, []) - self.stack_client.snapshot_delete = mock.Mock( - side_effect=heat_exc.HTTPNotFound()) + self.stack_client.snapshot_delete.side_effect = heat_exc.HTTPNotFound() self.assertRaises( exc.CommandError, self.cmd.take_action, diff --git a/heatclient/tests/unit/osc/v1/test_software_config.py b/heatclient/tests/unit/osc/v1/test_software_config.py index df27780..4a60f39 100644 --- a/heatclient/tests/unit/osc/v1/test_software_config.py +++ b/heatclient/tests/unit/osc/v1/test_software_config.py @@ -33,8 +33,7 @@ class TestDeleteConfig(TestConfig): def setUp(self): super(TestDeleteConfig, self).setUp() self.cmd = software_config.DeleteConfig(self.app, None) - self.mock_delete = mock.Mock() - self.mock_client.software_configs.delete = self.mock_delete + self.mock_delete = self.mock_client.software_configs.delete def test_config_delete(self): arglist = ['id_123'] @@ -71,8 +70,8 @@ class TestListConfig(TestConfig): def setUp(self): super(TestListConfig, self).setUp() self.cmd = software_config.ListConfig(self.app, None) - self.mock_client.software_configs.list = mock.Mock( - return_value=[software_configs.SoftwareConfig(None, {})]) + self.mock_client.software_configs.list.return_value = [ + software_configs.SoftwareConfig(None, {})] def test_config_list(self): arglist = [] @@ -99,9 +98,8 @@ class TestCreateConfig(TestConfig): def setUp(self): super(TestCreateConfig, self).setUp() self.cmd = software_config.CreateConfig(self.app, None) - self.mock_client.stacks.validate = mock.Mock() - self.mock_client.software_configs.create = mock.Mock( - return_value=software_configs.SoftwareConfig(None, {})) + self.mock_client.software_configs.create.return_value = \ + software_configs.SoftwareConfig(None, {}) def test_config_create(self): properties = { @@ -239,9 +237,8 @@ class TestConfigShow(TestConfig): def setUp(self): super(TestConfigShow, self).setUp() self.cmd = software_config.ShowConfig(self.app, None) - self.mock_client.software_configs.get = mock.Mock( - return_value=software_configs.SoftwareConfig(None, - self.response)) + self.mock_client.software_configs.get.return_value = \ + software_configs.SoftwareConfig(None, self.response) def test_config_show(self): arglist = ['96dfee3f-27b7-42ae-a03e-966226871ae6'] @@ -266,8 +263,8 @@ class TestConfigShow(TestConfig): def test_config_show_not_found(self): arglist = ['96dfee3f-27b7-42ae-a03e-966226871ae6'] parsed_args = self.check_parser(self.cmd, arglist, []) - self.mock_client.software_configs.get = mock.Mock( - side_effect=heat_exc.HTTPNotFound()) + self.mock_client.software_configs.get.side_effect = \ + heat_exc.HTTPNotFound() self.assertRaises( exc.CommandError, self.cmd.take_action, diff --git a/heatclient/tests/unit/osc/v1/test_software_deployment.py b/heatclient/tests/unit/osc/v1/test_software_deployment.py index e44f9a8..dc4c214 100644 --- a/heatclient/tests/unit/osc/v1/test_software_deployment.py +++ b/heatclient/tests/unit/osc/v1/test_software_deployment.py @@ -110,12 +110,12 @@ class TestDeploymentCreate(TestDeployment): def setUp(self): super(TestDeploymentCreate, self).setUp() self.cmd = software_deployment.CreateDeployment(self.app, None) - self.config_client.create = mock.MagicMock(return_value=( - software_configs.SoftwareConfig(None, self.config))) - self.config_client.get = mock.MagicMock(return_value=( - software_configs.SoftwareConfig(None, self.config))) - self.sd_client.create = mock.MagicMock(return_value=( - software_deployments.SoftwareDeployment(None, self.deployment))) + self.config_client.create.return_value = \ + software_configs.SoftwareConfig(None, self.config) + self.config_client.get.return_value = \ + software_configs.SoftwareConfig(None, self.config) + self.sd_client.create.return_value = \ + software_deployments.SoftwareDeployment(None, self.deployment) @mock.patch('heatclient.common.deployment_utils.build_signal_id', return_value='signal_id') @@ -226,8 +226,6 @@ class TestDeploymentDelete(TestDeployment): def test_deployment_delete_success(self): arglist = ['test_deployment'] parsed_args = self.check_parser(self.cmd, arglist, []) - self.sd_client.get = mock.Mock() - self.sd_client.delete = mock.Mock() self.cmd.take_action(parsed_args) self.sd_client.delete.assert_called_with( deployment_id='test_deployment') @@ -235,8 +233,6 @@ class TestDeploymentDelete(TestDeployment): def test_deployment_delete_multiple(self): arglist = ['test_deployment', 'test_deployment2'] parsed_args = self.check_parser(self.cmd, arglist, []) - self.sd_client.get = mock.Mock() - self.sd_client.delete = mock.Mock() self.cmd.take_action(parsed_args) self.sd_client.delete.assert_has_calls( [mock.call(deployment_id='test_deployment'), @@ -245,7 +241,6 @@ class TestDeploymentDelete(TestDeployment): def test_deployment_delete_not_found(self): arglist = ['test_deployment', 'test_deployment2'] parsed_args = self.check_parser(self.cmd, arglist, []) - self.sd_client.delete = mock.Mock() self.sd_client.delete.side_effect = heat_exc.HTTPNotFound() error = self.assertRaises( exc.CommandError, self.cmd.take_action, parsed_args) @@ -254,12 +249,8 @@ class TestDeploymentDelete(TestDeployment): def test_deployment_config_delete_failed(self): arglist = ['test_deployment'] parsed_args = self.check_parser(self.cmd, arglist, []) - self.config_client.delete = mock.Mock() self.config_client.delete.side_effect = heat_exc.HTTPNotFound() - error = self.assertRaises( - exc.CommandError, self.cmd.take_action, parsed_args) - self.assertEqual("Unable to delete 1 of the 1 deployments.", - str(error)) + self.assertIsNone(self.cmd.take_action(parsed_args)) class TestDeploymentList(TestDeployment): @@ -350,9 +341,9 @@ class TestDeploymentShow(TestDeployment): 'updated_time', 'status', 'status_reason', 'input_values', 'action'] parsed_args = self.check_parser(self.cmd, arglist, []) - self.sd_client.get = mock.Mock( - return_value=software_deployments.SoftwareDeployment( - None, self.get_response)) + self.sd_client.get.return_value = \ + software_deployments.SoftwareDeployment( + None, self.get_response) columns, data = self.cmd.take_action(parsed_args) self.sd_client.get.assert_called_with(**{ 'deployment_id': 'my_deployment', @@ -365,9 +356,9 @@ class TestDeploymentShow(TestDeployment): 'updated_time', 'status', 'status_reason', 'input_values', 'action', 'output_values'] parsed_args = self.check_parser(self.cmd, arglist, []) - self.sd_client.get = mock.Mock( - return_value=software_deployments.SoftwareDeployment( - None, self.get_response)) + self.sd_client.get.return_value = \ + software_deployments.SoftwareDeployment( + None, self.get_response) columns, data = self.cmd.take_action(parsed_args) self.sd_client.get.assert_called_once_with(**{ 'deployment_id': 'my_deployment', @@ -377,7 +368,6 @@ class TestDeploymentShow(TestDeployment): def test_deployment_not_found(self): arglist = ['my_deployment'] parsed_args = self.check_parser(self.cmd, arglist, []) - self.sd_client.get = mock.Mock() self.sd_client.get.side_effect = heat_exc.HTTPNotFound() self.assertRaises( exc.CommandError, @@ -390,7 +380,7 @@ class TestDeploymentMetadataShow(TestDeployment): def setUp(self): super(TestDeploymentMetadataShow, self).setUp() self.cmd = software_deployment.ShowMetadataDeployment(self.app, None) - self.sd_client.metadata = mock.Mock(return_value={}) + self.sd_client.metadata.return_value = {} def test_deployment_show_metadata(self): arglist = ['ec14c864-096e-4e27-bb8a-2c2b4dc6f3f5'] @@ -422,9 +412,9 @@ class TestDeploymentOutputShow(TestDeployment): def test_deployment_output_show(self): arglist = ['85c3a507-351b-4b28-a7d8-531c8d53f4e6', '--all', '--long'] parsed_args = self.check_parser(self.cmd, arglist, []) - self.sd_client.get = mock.Mock( - return_value=software_deployments.SoftwareDeployment( - None, self.get_response)) + self.sd_client.get.return_value = \ + software_deployments.SoftwareDeployment( + None, self.get_response) self.cmd.take_action(parsed_args) self.sd_client.get.assert_called_with(**{ 'deployment_id': '85c3a507-351b-4b28-a7d8-531c8d53f4e6' @@ -433,7 +423,6 @@ class TestDeploymentOutputShow(TestDeployment): def test_deployment_output_show_invalid(self): arglist = ['85c3a507-351b-4b28-a7d8-531c8d53f4e6'] parsed_args = self.check_parser(self.cmd, arglist, []) - self.sd_client.get = mock.Mock() error = self.assertRaises( exc.CommandError, self.cmd.take_action, @@ -444,7 +433,6 @@ class TestDeploymentOutputShow(TestDeployment): def test_deployment_output_show_not_found(self): arglist = ['85c3a507-351b-4b28-a7d8-531c8d53f4e6', '--all'] parsed_args = self.check_parser(self.cmd, arglist, []) - self.sd_client.get = mock.Mock() self.sd_client.get.side_effect = heat_exc.HTTPNotFound() self.assertRaises( exc.CommandError, diff --git a/heatclient/tests/unit/osc/v1/test_stack.py b/heatclient/tests/unit/osc/v1/test_stack.py index b5e9662..b6d31f7 100644 --- a/heatclient/tests/unit/osc/v1/test_stack.py +++ b/heatclient/tests/unit/osc/v1/test_stack.py @@ -56,12 +56,12 @@ class TestStackCreate(TestStack): def setUp(self): super(TestStackCreate, self).setUp() self.cmd = stack.CreateStack(self.app, None) - self.stack_client.create = mock.MagicMock( - return_value={'stack': {'id': '1234'}}) - self.stack_client.get = mock.MagicMock( - return_value={'stack_status': 'create_complete'}) - self.stack_client.preview = mock.MagicMock( - return_value=stacks.Stack(None, {'stack': {'id', '1234'}})) + self.stack_client.create.return_value = {'stack': {'id': '1234'}} + self.stack_client.get.return_value = { + 'stack_status': 'create_complete'} + self.stack_client.preview.return_value = stacks.Stack( + None, {'stack': {'id', '1234'}}) + stack._authenticated_fetcher = mock.MagicMock() def test_stack_create_defaults(self): arglist = ['my_stack', '-t', self.template_path] @@ -175,16 +175,15 @@ class TestStackUpdate(TestStack): def setUp(self): super(TestStackUpdate, self).setUp() self.cmd = stack.UpdateStack(self.app, None) - self.stack_client.update = mock.MagicMock( - return_value={'stack': {'id': '1234'}}) - self.stack_client.preview_update = mock.MagicMock( - return_value={'resource_changes': {'added': [], - 'deleted': [], - 'replaced': [], - 'unchanged': [], - 'updated': []}}) - self.stack_client.get = mock.MagicMock( - return_value={'stack_status': 'create_complete'}) + self.stack_client.update.return_value = {'stack': {'id': '1234'}} + self.stack_client.preview_update.return_value = { + 'resource_changes': {'added': [], + 'deleted': [], + 'replaced': [], + 'unchanged': [], + 'updated': []}} + self.stack_client.get.return_value = { + 'stack_status': 'create_complete'} def test_stack_update_defaults(self): arglist = ['my_stack', '-t', self.template_path] @@ -384,8 +383,8 @@ class TestStackShow(TestStack): def setUp(self): super(TestStackShow, self).setUp() self.cmd = stack.ShowStack(self.app, None) - self.stack_client.get = mock.Mock( - return_value=stacks.Stack(None, self.get_response)) + self.stack_client.get.return_value = stacks.Stack( + None, self.get_response) def test_stack_show(self): arglist = ['--format', self.format, 'my_stack'] @@ -434,8 +433,7 @@ class TestStackList(TestStack): def setUp(self): super(TestStackList, self).setUp() self.cmd = stack.ListStack(self.app, None) - self.stack_client.list = mock.MagicMock( - return_value=[stacks.Stack(None, self.data)]) + self.stack_client.list.return_value = [stacks.Stack(None, self.data)] utils.get_dict_properties = mock.MagicMock(return_value='') def test_stack_list_defaults(self): @@ -546,9 +544,7 @@ class TestStackDelete(TestStack): def setUp(self): super(TestStackDelete, self).setUp() self.cmd = stack.DeleteStack(self.app, None) - self.stack_client.delete = mock.MagicMock() - self.stack_client.get = mock.MagicMock( - side_effect=heat_exc.HTTPNotFound) + self.stack_client.get.side_effect = heat_exc.HTTPNotFound def test_stack_delete(self): arglist = ['stack1', 'stack2', 'stack3'] @@ -661,8 +657,7 @@ class TestStackAdopt(TestStack): def setUp(self): super(TestStackAdopt, self).setUp() self.cmd = stack.AdoptStack(self.app, None) - self.stack_client.create = mock.MagicMock( - return_value={'stack': {'id': '1234'}}) + self.stack_client.create.return_value = {'stack': {'id': '1234'}} def test_stack_adopt_defaults(self): arglist = ['my_stack', '--adopt-file', self.adopt_file] @@ -691,8 +686,8 @@ class TestStackAdopt(TestStack): 'Stack my_stack ADOPT_COMPLETE')) def test_stack_adopt_wait(self, mock_poll): arglist = ['my_stack', '--adopt-file', self.adopt_file, '--wait'] - self.stack_client.get = mock.MagicMock(return_value=( - stacks.Stack(None, {'stack_status': 'ADOPT_COMPLETE'}))) + self.stack_client.get.return_value = \ + stacks.Stack(None, {'stack_status': 'ADOPT_COMPLETE'}) parsed_args = self.check_parser(self.cmd, arglist, []) self.cmd.take_action(parsed_args) @@ -705,8 +700,8 @@ class TestStackAdopt(TestStack): 'Stack my_stack ADOPT_FAILED')) def test_stack_adopt_wait_fail(self, mock_poll): arglist = ['my_stack', '--adopt-file', self.adopt_file, '--wait'] - self.stack_client.get = mock.MagicMock(return_value=( - stacks.Stack(None, {'stack_status': 'ADOPT_FAILED'}))) + self.stack_client.get.return_value = \ + stacks.Stack(None, {'stack_status': 'ADOPT_FAILED'}) parsed_args = self.check_parser(self.cmd, arglist, []) self.assertRaises(exc.CommandError, self.cmd.take_action, parsed_args) @@ -722,7 +717,7 @@ class TestStackAbandon(TestStack): def setUp(self): super(TestStackAbandon, self).setUp() self.cmd = stack.AbandonStack(self.app, None) - self.stack_client.abandon = mock.MagicMock(return_value=self.response) + self.stack_client.abandon.return_value = self.response def test_stack_abandon(self): arglist = ['my_stack'] @@ -779,8 +774,7 @@ class TestStackOutputShow(TestStack): def setUp(self): super(TestStackOutputShow, self).setUp() self.cmd = stack.OutputShowStack(self.app, None) - self.stack_client.get = mock.MagicMock( - return_value=stacks.Stack(None, self.response)) + self.stack_client.get.return_value = stacks.Stack(None, self.response) def test_stack_output_show_no_output(self): arglist = ['my_stack'] @@ -811,8 +805,8 @@ class TestStackOutputShow(TestStack): def test_stack_output_show_output(self): arglist = ['my_stack', 'output1'] - self.stack_client.output_show = mock.MagicMock( - return_value={'output': self.outputs[0]}) + self.stack_client.output_show.return_value = { + 'output': self.outputs[0]} parsed_args = self.check_parser(self.cmd, arglist, []) columns, outputs = self.cmd.take_action(parsed_args) @@ -832,8 +826,8 @@ class TestStackOutputShow(TestStack): def test_stack_output_show_output_error(self): arglist = ['my_stack', 'output2'] - self.stack_client.output_show = mock.MagicMock( - return_value={'output': self.outputs[1]}) + self.stack_client.output_show.return_value = { + 'output': self.outputs[1]} parsed_args = self.check_parser(self.cmd, arglist, []) error = self.assertRaises(exc.CommandError, @@ -922,9 +916,9 @@ class TestStackTemplateShow(TestStack): def test_stack_template_show_full_template(self): arglist = ['my_stack'] - self.stack_client.template = mock.MagicMock( - return_value=yaml.load(inline_templates.FULL_TEMPLATE, - Loader=template_format.yaml_loader)) + self.stack_client.template.return_value = yaml.load( + inline_templates.FULL_TEMPLATE, + Loader=template_format.yaml_loader) parsed_args = self.check_parser(self.cmd, arglist, []) columns, outputs = self.cmd.take_action(parsed_args) @@ -934,9 +928,9 @@ class TestStackTemplateShow(TestStack): def test_stack_template_show_short_template(self): arglist = ['my_stack'] - self.stack_client.template = mock.MagicMock( - return_value=yaml.load(inline_templates.SHORT_TEMPLATE, - Loader=template_format.yaml_loader)) + self.stack_client.template.return_value = yaml.load( + inline_templates.SHORT_TEMPLATE, + Loader=template_format.yaml_loader) parsed_args = self.check_parser(self.cmd, arglist, []) columns, outputs = self.cmd.take_action(parsed_args) @@ -946,8 +940,7 @@ class TestStackTemplateShow(TestStack): def test_stack_template_show_not_found(self): arglist = ['my_stack'] - self.stack_client.template = mock.MagicMock( - side_effect=heat_exc.HTTPNotFound) + self.stack_client.template.side_effect = heat_exc.HTTPNotFound parsed_args = self.check_parser(self.cmd, arglist, []) self.assertRaises(exc.CommandError, self.cmd.take_action, parsed_args) @@ -969,9 +962,8 @@ class _TestStackCheckBase(object): def _setUp(self, cmd, action, action_name=None): self.cmd = cmd self.action = action - self.mock_client.stacks.get = mock.Mock( - return_value=self.stack) self.action_name = action_name + self.mock_client.stacks.get.return_value = self.stack def _test_stack_action(self, get_call_count=1): arglist = ['my_stack'] @@ -1041,7 +1033,6 @@ class TestStackSuspend(_TestStackCheckBase, TestStack): def setUp(self): super(TestStackSuspend, self).setUp() - self.mock_client.actions.suspend = mock.Mock() self._setUp( stack.SuspendStack(self.app, None), self.mock_client.actions.suspend, @@ -1068,7 +1059,6 @@ class TestStackResume(_TestStackCheckBase, TestStack): def setUp(self): super(TestStackResume, self).setUp() - self.mock_client.actions.resume = mock.Mock() self._setUp( stack.ResumeStack(self.app, None), self.mock_client.actions.resume, @@ -1103,14 +1093,13 @@ class TestStackCancel(_TestStackCheckBase, TestStack): def setUp(self): super(TestStackCancel, self).setUp() - self.mock_client.actions.cancel_update = mock.Mock() self._setUp( stack.CancelStack(self.app, None), self.mock_client.actions.cancel_update, 'ROLLBACK' ) - self.mock_client.stacks.get = mock.Mock( - return_value=self.stack_update_in_progress) + self.mock_client.stacks.get.return_value = \ + self.stack_update_in_progress def test_stack_cancel(self): self._test_stack_action(2) @@ -1128,8 +1117,7 @@ class TestStackCancel(_TestStackCheckBase, TestStack): self._test_stack_action_exception() def test_stack_cancel_unsupported_state(self): - self.mock_client.stacks.get = mock.Mock( - return_value=self.stack) + self.mock_client.stacks.get.return_value = self.stack error = self.assertRaises(exc.CommandError, self._test_stack_action, 2) @@ -1142,7 +1130,6 @@ class TestStackCheck(_TestStackCheckBase, TestStack): def setUp(self): super(TestStackCheck, self).setUp() - self.mock_client.actions.check = mock.Mock() self._setUp( stack.CheckStack(self.app, None), self.mock_client.actions.check, @@ -1219,12 +1206,9 @@ class TestStackHookPoll(TestStack): def setUp(self): super(TestStackHookPoll, self).setUp() self.cmd = stack.StackHookPoll(self.app, None) - self.mock_client.stacks.get = mock.Mock( - return_value=self.stack) - self.mock_client.events.list = mock.Mock( - return_value=[self.event0, self.event1]) - self.mock_client.resources.list = mock.Mock( - return_value=[self.resource]) + self.mock_client.stacks.get.return_value = self.stack + self.mock_client.events.list.return_value = [self.event0, self.event1] + self.mock_client.resources.list.return_value = [self.resource] def test_hook_poll(self): expected_columns = ['Resource Name'] + self.columns @@ -1267,11 +1251,8 @@ class TestStackHookClear(TestStack): def setUp(self): super(TestStackHookClear, self).setUp() self.cmd = stack.StackHookClear(self.app, None) - self.mock_client.stacks.get = mock.Mock( - return_value=self.stack) - self.mock_client.resources.signal = mock.Mock() - self.mock_client.resources.list = mock.Mock( - return_value=[self.resource]) + self.mock_client.stacks.get.return_value = self.stack + self.mock_client.resources.list.return_value = [self.resource] def test_hook_clear(self): arglist = ['my_stack', 'resource'] diff --git a/heatclient/tests/unit/osc/v1/test_template.py b/heatclient/tests/unit/osc/v1/test_template.py index c00774f..c69637d 100644 --- a/heatclient/tests/unit/osc/v1/test_template.py +++ b/heatclient/tests/unit/osc/v1/test_template.py @@ -38,7 +38,7 @@ class TestTemplateVersionList(TestTemplate): super(TestTemplateVersionList, self).setUp() tv1 = template_versions.TemplateVersion(None, self.defaults[0]) tv2 = template_versions.TemplateVersion(None, self.defaults[1]) - self.template_versions.list = mock.MagicMock(return_value=[tv1, tv2]) + self.template_versions.list.return_value = [tv1, tv2] self.cmd = template.VersionList(self.app, None) def test_version_list(self): @@ -61,7 +61,7 @@ class TestTemplateFunctionList(TestTemplate): super(TestTemplateFunctionList, self).setUp() tv1 = template_versions.TemplateVersion(None, self.defaults[0]) tv2 = template_versions.TemplateVersion(None, self.defaults[1]) - self.template_versions.get = mock.MagicMock(return_value=[tv1, tv2]) + self.template_versions.get.return_value = [tv1, tv2] self.cmd = template.FunctionList(self.app, None) def test_function_list(self): diff --git a/heatclient/v1/shell.py b/heatclient/v1/shell.py index 9d5ff60..f2d5a52 100644 --- a/heatclient/v1/shell.py +++ b/heatclient/v1/shell.py @@ -938,7 +938,7 @@ def do_template_validate(hc, args): @utils.arg('-f', '--filter', metavar='<KEY=VALUE>', help=_('Filter parameters to apply on returned resources based on' ' their name, status, type, action, id and' - ' physcial_resource_id. This can be specified multiple' + ' physical_resource_id. This can be specified multiple' ' times.'), action='append') def do_resource_list(hc, args): @@ -77,6 +77,14 @@ openstack.orchestration.v1 = stack_template_show = heatclient.osc.v1.stack:TemplateShowStack stack_update = heatclient.osc.v1.stack:UpdateStack +heatclient.event.formatter.list = + log = heatclient.osc.v1.event:LogFormatter + table = cliff.formatters.table:TableFormatter + csv = cliff.formatters.commaseparated:CSVLister + value = cliff.formatters.value:ValueFormatter + yaml = cliff.formatters.yaml_format:YAMLFormatter + json = cliff.formatters.json_format:JSONFormatter + [global] setup-hooks = pbr.hooks.setup_hook diff --git a/test-requirements.txt b/test-requirements.txt index 2d94e34..7321e4d 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -6,9 +6,9 @@ hacking<0.11,>=0.10.0 coverage>=3.6 # Apache-2.0 discover # BSD -fixtures<2.0,>=1.3.1 # Apache-2.0/BSD +fixtures>=3.0.0 # Apache-2.0/BSD requests-mock>=0.7.0 # Apache-2.0 -mock>=1.2 # BSD +mock>=2.0 # BSD mox3>=0.7.0 # Apache-2.0 oslosphinx!=3.4.0,>=2.5.0 # Apache-2.0 oslotest>=1.10.0 # Apache-2.0 |