Debian Codegraph @

ansible_collections/community/general/tests/unit/plugins/lookup/test_dependent.py

raw
1 # Copyright (c) 2020-2021, Felix Fontein <[email protected]>
2 # GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
3 # SPDX-License-Identifier: GPL-3.0-or-later
4
5 # Make coding more python3-ish
6 from __future__ import annotations
7
8 from unittest import TestCase
9
10 from ansible.plugins.loader import lookup_loader
11 from ansible.template import Templar
12 from ansible_collections.community.internal_test_tools.tests.unit.utils.trust import make_trusted
13
14
15 class TestLookupModule(TestCase):
16 def setUp(self):
17 templar = Templar(loader=None)
18 self.lookup = lookup_loader.get("community.general.dependent", templar=templar)
19
20 def test_empty(self):
21 self.assertListEqual(self.lookup.run([], None), [])
22
23 def test_simple(self):
24 self.assertListEqual(
25 self.lookup.run(
26 [
27 {"a": make_trusted("[1, 2]")},
28 {"b": make_trusted("[item.a + 3, item.a + 6]")},
29 {"c": make_trusted("[item.a + item.b * 10]")},
30 ],
31 {},
32 ),
33 [
34 {"a": 1, "b": 4, "c": 41},
35 {"a": 1, "b": 7, "c": 71},
36 {"a": 2, "b": 5, "c": 52},
37 {"a": 2, "b": 8, "c": 82},
38 ],
39 )