Debian Codegraph @

test/units/playbook/test_playbook.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 unittest
21 from ansible.errors import AnsibleParserError
22 from ansible.playbook import Playbook
23 from ansible.vars.manager import VariableManager
24
25 from units.mock.loader import DictDataLoader
26
27
28 class TestPlaybook(unittest.TestCase):
29
30 def test_empty_playbook(self):
31 fake_loader = DictDataLoader({})
32 p = Playbook(loader=fake_loader)
33
34 def test_basic_playbook(self):
35 fake_loader = DictDataLoader({
36 "test_file.yml": """
37 - hosts: all
38 """,
39 })
40 p = Playbook.load("test_file.yml", loader=fake_loader)
41 plays = p.get_plays()
42
43 def test_bad_playbook_files(self):
44 fake_loader = DictDataLoader({
45 # represents a playbook which is not a list of plays
46 "bad_list.yml": """
47 foo: bar
48
49 """,
50 # represents a playbook where a play entry is mis-formatted
51 "bad_entry.yml": """
52 -
53 - "This should be a mapping..."
54
55 """,
56 })
57 vm = VariableManager()
58 self.assertRaises(AnsibleParserError, Playbook.load, "bad_list.yml", vm, fake_loader)
59 self.assertRaises(AnsibleParserError, Playbook.load, "bad_entry.yml", vm, fake_loader)