Debian Codegraph @

test/units/playbook/test_block.py

raw
1 # (c) 2012-2014, Michael DeHaan <[email protected]>
2 #
3 # This file is part of Ansible
4 #
5 # Ansible is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
9 #
10 # Ansible is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with Ansible. If not, see <http://www.gnu.org/licenses/>.
17
18 from __future__ import annotations
19
20 import pytest
21 import unittest
22
23 from ansible.playbook.block import Block
24 from ansible.playbook.task import Task
25
26
27 @pytest.mark.usefixtures('collection_loader')
28 class TestBlock(unittest.TestCase):
29
30 def test_construct_empty_block(self):
31 b = Block()
32
33 def test_construct_block_with_role(self):
34 pass
35
36 def test_load_block_simple(self):
37 ds = dict(
38 block=[],
39 rescue=[],
40 always=[],
41 # otherwise=[],
42 )
43 b = Block.load(ds)
44 self.assertEqual(b.block, [])
45 self.assertEqual(b.rescue, [])
46 self.assertEqual(b.always, [])
47 # not currently used
48 # self.assertEqual(b.otherwise, [])
49
50 def test_load_block_with_tasks(self):
51 ds = dict(
52 block=[dict(action='block')],
53 rescue=[dict(action='rescue')],
54 always=[dict(action='always')],
55 # otherwise=[dict(action='otherwise')],
56 )
57 b = Block.load(ds)
58 self.assertEqual(len(b.block), 1)
59 self.assertIsInstance(b.block[0], Task)
60 self.assertEqual(len(b.rescue), 1)
61 self.assertIsInstance(b.rescue[0], Task)
62 self.assertEqual(len(b.always), 1)
63 self.assertIsInstance(b.always[0], Task)
64 # not currently used
65 # self.assertEqual(len(b.otherwise), 1)
66 # self.assertIsInstance(b.otherwise[0], Task)
67
68 def test_load_implicit_block(self):
69 ds = [dict(action='foo')]
70 b = Block.load(ds)
71 self.assertEqual(len(b.block), 1)
72 self.assertIsInstance(b.block[0], Task)