2014-10-16 19:08:33 +00:00
|
|
|
# (c) 2012-2014, Michael DeHaan <michael.dehaan@gmail.com>
|
|
|
|
#
|
|
|
|
# This file is part of Ansible
|
|
|
|
#
|
|
|
|
# Ansible is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# Ansible is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
# Make coding more python3-ish
|
|
|
|
from __future__ import (absolute_import, division, print_function)
|
|
|
|
__metaclass__ = type
|
|
|
|
|
2017-05-30 17:05:19 +00:00
|
|
|
from ansible.compat.tests import unittest
|
2014-10-16 19:08:33 +00:00
|
|
|
from ansible.playbook.block import Block
|
|
|
|
from ansible.playbook.task import Task
|
2017-05-30 17:05:19 +00:00
|
|
|
|
2014-10-16 19:08:33 +00:00
|
|
|
|
|
|
|
class TestBlock(unittest.TestCase):
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def test_construct_empty_block(self):
|
|
|
|
b = Block()
|
|
|
|
|
|
|
|
def test_construct_block_with_role(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def test_load_block_simple(self):
|
|
|
|
ds = dict(
|
2017-05-30 17:05:19 +00:00
|
|
|
block=[],
|
|
|
|
rescue=[],
|
|
|
|
always=[],
|
|
|
|
# otherwise=[],
|
2014-10-16 19:08:33 +00:00
|
|
|
)
|
|
|
|
b = Block.load(ds)
|
2014-10-19 05:14:30 +00:00
|
|
|
self.assertEqual(b.block, [])
|
2014-10-16 19:08:33 +00:00
|
|
|
self.assertEqual(b.rescue, [])
|
2014-10-19 05:14:30 +00:00
|
|
|
self.assertEqual(b.always, [])
|
|
|
|
# not currently used
|
2017-05-30 17:05:19 +00:00
|
|
|
# self.assertEqual(b.otherwise, [])
|
2014-10-16 19:08:33 +00:00
|
|
|
|
|
|
|
def test_load_block_with_tasks(self):
|
|
|
|
ds = dict(
|
2017-05-30 17:05:19 +00:00
|
|
|
block=[dict(action='block')],
|
|
|
|
rescue=[dict(action='rescue')],
|
|
|
|
always=[dict(action='always')],
|
|
|
|
# otherwise=[dict(action='otherwise')],
|
2014-10-16 19:08:33 +00:00
|
|
|
)
|
|
|
|
b = Block.load(ds)
|
2014-10-19 05:14:30 +00:00
|
|
|
self.assertEqual(len(b.block), 1)
|
2015-05-08 20:49:10 +00:00
|
|
|
self.assertIsInstance(b.block[0], Task)
|
2014-10-16 19:08:33 +00:00
|
|
|
self.assertEqual(len(b.rescue), 1)
|
2015-05-08 20:49:10 +00:00
|
|
|
self.assertIsInstance(b.rescue[0], Task)
|
2014-10-19 05:14:30 +00:00
|
|
|
self.assertEqual(len(b.always), 1)
|
2015-05-08 20:49:10 +00:00
|
|
|
self.assertIsInstance(b.always[0], Task)
|
2014-10-19 05:14:30 +00:00
|
|
|
# not currently used
|
2017-05-30 17:05:19 +00:00
|
|
|
# self.assertEqual(len(b.otherwise), 1)
|
|
|
|
# self.assertIsInstance(b.otherwise[0], Task)
|
2014-10-19 05:14:30 +00:00
|
|
|
|
|
|
|
def test_load_implicit_block(self):
|
|
|
|
ds = [dict(action='foo')]
|
|
|
|
b = Block.load(ds)
|
|
|
|
self.assertEqual(len(b.block), 1)
|
2015-05-08 20:49:10 +00:00
|
|
|
self.assertIsInstance(b.block[0], Task)
|
2014-10-16 19:08:33 +00:00
|
|
|
|
2016-10-21 02:54:16 +00:00
|
|
|
def test_deserialize(self):
|
|
|
|
ds = dict(
|
2017-05-30 17:05:19 +00:00
|
|
|
block=[dict(action='block')],
|
|
|
|
rescue=[dict(action='rescue')],
|
|
|
|
always=[dict(action='always')],
|
2016-10-21 02:54:16 +00:00
|
|
|
)
|
|
|
|
b = Block.load(ds)
|
2017-05-30 17:05:19 +00:00
|
|
|
data = dict(parent=ds, parent_type='Block')
|
2016-10-21 02:54:16 +00:00
|
|
|
b.deserialize(data)
|
|
|
|
self.assertIsInstance(b._parent, Block)
|