Remove commands test cases

These three commands (tobiko-create, tobiko-list, tobiko-delete) are
going to be replaced by the more generic tobiko-fixture command.

Change-Id: I6c77ad84a3146416a56d4b1ad74ab30bfae45fda
This commit is contained in:
Federico Ressi 2019-03-27 09:13:44 +01:00
parent 404e0e2e0b
commit dc0ef0e16f
3 changed files with 0 additions and 333 deletions

View File

@ -1,107 +0,0 @@
# Copyright (c) 2018 Red Hat
# All Rights Reserved.
#
# 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.
from __future__ import absolute_import
from heatclient import exc
import mock
from tobiko.cmd import create
from tobiko.common.managers import stack as stack_manager
from tobiko.common import constants
from tobiko.tests.cmd import test_base
class CreateTest(test_base.TobikoCMDTest):
command_name = 'tobiko-create'
command_class = create.CreateUtil
def test_init(self, argv=None, all_stacks=False, stack=None, wait=False):
# pylint: disable=arguments-differ,no-member
cmd = super(CreateTest, self).test_init(argv=argv)
self.assertIsNotNone(cmd.parser)
self.assertIs(all_stacks, cmd.args.all)
self.assertEqual(stack, cmd.args.stack)
self.assertIs(wait, cmd.args.wait)
return cmd
def test_init_with_all(self):
self.test_init(argv=['--all'], all_stacks=True)
def test_init_with_stack(self):
self.test_init(argv=['--stack', 'my-stack'], stack='my-stack')
def test_init_with_wait(self):
self.test_init(argv=['--wait'], wait=True)
def test_init_with_w(self):
self.test_init(argv=['-w'], wait=True)
def test_main(self, argv=None, stack_names=None, walk_dir=True,
wait=False):
if stack_names is None:
stack_names = ['test_mtu', 'test_floatingip']
self.patch_argv(argv=argv)
mock_sleep = self.patch('time.sleep')
mock_walk = self.patch('os.walk', return_value=[
(None, None, [(name + '.yaml') for name in stack_names])])
def mock_client_get():
for name in stack_names:
# This would cause to create stack
yield exc.HTTPNotFound
# This would cause to wait for CREATE_COMPLETE status
yield mock.Mock(stack_status=stack_manager.CREATE_IN_PROGRESS,
name=name)
if wait:
# Break wait for stack status loop
yield mock.Mock(stack_status=stack_manager.CREATE_COMPLETE,
name=name)
client = self.patch_get_heat_client().return_value
client.stacks.get.side_effect = mock_client_get()
create.main()
# Check stack is created
client.stacks.create.assert_has_calls(
[mock.call(parameters=constants.DEFAULT_PARAMS,
stack_name=stack_name,
template=mock.ANY)
for stack_name in stack_names])
if walk_dir:
mock_walk.assert_called()
if wait:
mock_sleep.assert_called()
def test_main_with_stack(self):
self.test_main(argv=['--stack', 'test_floatingip'],
stack_names=['test_floatingip'], walk_dir=False)
def test_main_with_all(self):
self.test_main(argv=['--all'],
stack_names=['test_mtu', 'test_security_groups'])
def test_main_with_wait(self):
self.test_main(argv=['--wait'], wait=True)
def test_main_with_w(self):
self.test_main(argv=['-w'], wait=True)

View File

@ -1,123 +0,0 @@
# Copyright (c) 2018 Red Hat
# All Rights Reserved.
#
# 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.
from __future__ import absolute_import
from heatclient import exc
import mock
from tobiko.cmd import delete
from tobiko.common.managers import stack as stack_manager
from tobiko.tests.cmd import test_base
class DeleteTest(test_base.TobikoCMDTest):
command_name = 'tobiko-delete'
command_class = delete.DeleteUtil
def test_init(self, argv=None, all_stacks=False, stack=None, wait=False):
# pylint: disable=arguments-differ,no-member
cmd = super(DeleteTest, self).test_init(argv=argv)
self.assertIsNotNone(cmd.parser)
self.assertIs(all_stacks, cmd.args.all)
self.assertEqual(stack, cmd.args.stack)
self.assertIs(wait, cmd.args.wait)
return cmd
def test_init_with_all(self):
self.test_init(argv=['--all'], all_stacks=True)
def test_init_with_stack(self):
self.test_init(argv=['--stack', 'my-stack'], stack='my-stack')
def test_init_with_wait(self):
self.test_init(argv=['--wait'], wait=True)
def test_init_with_w(self):
self.test_init(argv=['-w'], wait=True)
def test_main(self, argv=None, stack_names=None, walk_dir=True,
wait=False):
if stack_names is None:
stack_names = ['test_mtu', 'test_floatingip']
self.patch_argv(argv=argv)
mock_sleep = self.patch('time.sleep')
mock_walk = self.patch('os.walk', return_value=[
(None, None, [(name + '.yaml') for name in stack_names])])
client = self.patch_get_heat_client().return_value
client.stacks.list.return_value = [mock.Mock(stack_name=stack_name)
for stack_name in stack_names[::2]]
def client_get():
for i, name in enumerate(stack_names):
if wait:
# This would cause to wait for DELETE_COMPLETE status
yield mock.Mock(
stack_status=stack_manager.DELETE_IN_PROGRESS,
name=name)
if i % 2:
# Break wait for stack status loop with DELETE_COMPLETE
yield mock.Mock(
stack_status=stack_manager.DELETE_COMPLETE,
name=name)
else:
# Break wait for stack status loop with HTTPNotFound
yield exc.HTTPNotFound
client.stacks.get.side_effect = client_get()
delete.main()
# Check stack is deleted
client.stacks.delete.assert_has_calls(
[mock.call(stack_name)
for stack_name in stack_names[::2]])
if walk_dir:
mock_walk.assert_called()
client.stacks.list.assert_called_once_with()
else:
client.stacks.list.assert_not_called()
if wait:
mock_sleep.assert_called()
def test_main_with_stack(self):
self.test_main(argv=['--stack', 'test_floatingip'],
stack_names=['test_floatingip'],
walk_dir=False)
def test_main_with_all(self):
self.test_main(argv=['--all'],
stack_names=['test_mtu', 'test_security_groups',
'test_floatingip'])
def test_main_with_wait(self):
self.test_main(argv=['--wait'],
stack_names=['test_mtu', 'test_security_groups',
'test_floatingip'],
wait=True)
def test_main_with_w(self):
self.test_main(argv=['-w'],
stack_names=['test_mtu', 'test_security_groups',
'test_floatingip'],
wait=True)

View File

@ -1,103 +0,0 @@
# Copyright (c) 2018 Red Hat
# All Rights Reserved.
#
# 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.
from __future__ import absolute_import
import mock
from tobiko.cmd import list as list_cmd
from tobiko.common.managers import stack
from tobiko.tests.cmd import test_base
class ListTest(test_base.TobikoCMDTest):
command_name = 'tobiko-list'
command_class = list_cmd.ListUtil
def test_init(self, argv=None, action=None):
# pylint: disable=arguments-differ,no-member
cmd = super(ListTest, self).test_init(argv=argv)
self.assertIsNotNone(cmd.parser)
self.assertEqual(action, cmd.args.action)
def test_init_with_stacks(self):
self.test_init(argv=['--stacks'],
action='list_stacks')
def test_init_with_s(self):
self.test_init(argv=['--stacks'],
action='list_stacks')
def test_init_with_templates(self):
self.test_init(argv=['--templates'],
action='list_templates')
def test_init_with_t(self):
self.test_init(argv=['-t'],
action='list_templates')
def test_main(self, argv=None, stack_names=None, show_stacks=None):
if stack_names is None:
stack_names = ['test_mtu', 'test_floatingip']
self.patch_argv(argv=argv)
client = self.patch_get_heat_client().return_value
# Break wait for stack status loop
client.stacks.get().stack_status = stack.CREATE_COMPLETE
client.stacks.list.return_value = [
mock.Mock(stack_name=stack_name)
for stack_name in stack_names[::2]]
mock_walk = self.patch('os.walk',
return_value=[(None, None, [(name + '.yaml')
for name in stack_names])])
mock_stdout_write = self.patch('sys.stdout.write')
list_cmd.main()
if show_stacks:
mock_stdout_write.assert_has_calls(
[mock.call(stack_name + '\n')
for stack_name in stack_names[::2]])
else:
mock_stdout_write.assert_has_calls(
[mock.call(stack_name + '.yaml\n')
for stack_name in stack_names])
mock_walk.assert_called()
def test_main_with_stacks(self):
self.test_main(argv=['--stack'],
stack_names=['test_floatingip', 'test_mtu'],
show_stacks=True)
def test_main_with_s(self):
self.test_main(argv=['-s'],
stack_names=['test_floatingip', 'test_security_groups'],
show_stacks=True)
def test_main_with_templates(self):
self.test_main(argv=['--templates'],
stack_names=['test_floatingip', 'test_mtu'],
show_stacks=False)
def test_main_with_t(self):
self.test_main(argv=['-t'],
stack_names=['test_floatingip', 'test_security_groups'],
show_stacks=False)