Debian Codegraph @

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

raw
1 # Copyright (c) 2020, Adam Migus <[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 from unittest.mock import (
10 MagicMock,
11 patch,
12 )
13
14 from ansible.plugins.loader import lookup_loader
15
16 from ansible_collections.community.general.plugins.lookup import dsv
17
18
19 class MockSecretsVault(MagicMock):
20 RESPONSE = '{"foo": "bar"}'
21
22 def get_secret_json(self, path):
23 return self.RESPONSE
24
25
26 class TestLookupModule(TestCase):
27 def setUp(self):
28 dsv.sdk_is_missing = False
29 self.lookup = lookup_loader.get("community.general.dsv")
30
31 @patch(
32 "ansible_collections.community.general.plugins.lookup.dsv.LookupModule.Client",
33 MockSecretsVault(),
34 )
35 def test_get_secret_json(self):
36 self.assertListEqual(
37 [MockSecretsVault.RESPONSE],
38 self.lookup.run(
39 ["/dummy"],
40 [],
41 **{
42 "tenant": "dummy",
43 "client_id": "dummy",
44 "client_secret": "dummy",
45 },
46 ),
47 )