Files
deb-python-openstacksdk/openstack/tests/unit/orchestration/v1/test_proxy.py
Brian Curtin 5bb3cb0e27 Argument consistency in test_proxy_base
This change brings a few more test methods to consistency in ordering of
arguments and the use of the default mock_method argument.

Note: this doesn't touch verify_find yet because the implementations
don't use BaseProxy, yet.

Change-Id: I27d3e8d43a5406b24e9b82fa3c59c60ad8e6c3f0
2015-07-09 11:36:48 -05:00

99 lines
3.8 KiB
Python

# 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
import six
from openstack import exceptions
from openstack.orchestration.v1 import _proxy
from openstack.orchestration.v1 import resource
from openstack.orchestration.v1 import stack
from openstack.tests.unit import test_proxy_base
class TestOrchestrationProxy(test_proxy_base.TestProxyBase):
def setUp(self):
super(TestOrchestrationProxy, self).setUp()
self.proxy = _proxy.Proxy(self.session)
def test_stack_create_attrs(self):
self.verify_create(self.proxy.create_stack, stack.Stack)
def test_stack_find(self):
self.verify_find('openstack.orchestration.v1.stack.Stack.find',
self.proxy.find_stack)
def test_stacks(self):
self.verify_list(self.proxy.stacks, stack.Stack, paginated=False)
def test_stack_get(self):
self.verify_get(self.proxy.get_stack, stack.Stack)
def test_stack_delete(self):
self.verify_delete(self.proxy.delete_stack, stack.Stack, False)
def test_stack_delete_ignore(self):
self.verify_delete(self.proxy.delete_stack, stack.Stack, True)
def test_stack_wait_for(self):
value = stack.Stack(attrs={'id': '1234'})
self.verify_wait_for_status(
self.proxy.wait_for_stack,
method_args=[value],
expected_args=[value, 'CREATE_COMPLETE', ['CREATE_FAILED'],
2, 120])
@mock.patch.object(stack.Stack, 'from_id')
@mock.patch.object(stack.Stack, 'find')
def test_resources_with_stack_object(self, mock_find, mock_from):
stack_id = '1234'
stack_name = 'test_stack'
stack_identity = {'id': stack_id, 'name': stack_name}
stk = stack.Stack(attrs=stack_identity)
mock_from.return_value = stk
path_args = {'stack_id': stk.id, 'stack_name': stk.name}
self.verify_list(self.proxy.resources, resource.Resource,
paginated=False,
method_args=[stk],
expected_kwargs={'path_args': path_args})
self.assertEqual(0, mock_find.call_count)
@mock.patch.object(stack.Stack, 'find')
def test_resources_with_stack_name(self, mock_find):
stack_name = 'test_stack'
stack_id = '1234'
stack_identity = {'id': stack_id, 'stack_name': stack_name}
stk = stack.Stack(attrs=stack_identity)
mock_find.return_value = stk
path_args = {'stack_id': stack_id, 'stack_name': stack_name}
self.verify_list(self.proxy.resources, resource.Resource,
paginated=False,
method_args=[stack_name],
expected_kwargs={'path_args': path_args})
mock_find.assert_called_once_with(mock.ANY, stack_name)
@mock.patch.object(stack.Stack, 'find')
@mock.patch.object(resource.Resource, 'list')
def test_resources_stack_not_found(self, mock_list, mock_find):
stack_name = 'test_stack'
mock_find.side_effect = exceptions.ResourceNotFound(
'No stack found for test_stack')
ex = self.assertRaises(exceptions.ResourceNotFound,
self.proxy.resources, stack_name)
self.assertEqual('ResourceNotFound: No stack found for test_stack',
six.text_type(ex))