Debian Codegraph @

ansible_collections/community/general/tests/unit/plugins/module_utils/test__onepassword.py

raw
1 # Copyright (c) 2022 Ansible Project
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 from __future__ import annotations
6
7 import os
8
9 import pytest
10
11 from ansible_collections.community.general.plugins.module_utils._onepassword import OnePasswordConfig
12
13
14 @pytest.fixture
15 def os_expanduser(mocker):
16 def _os_expanduser(path):
17 return path.replace("~", "/home/testuser")
18
19 mocker.patch("os.path.expanduser", side_effect=_os_expanduser)
20
21
22 @pytest.fixture
23 def exists(mocker):
24 def _exists(path):
25 if "op/" in path:
26 return True
27
28 return os.path.exists(path)
29
30
31 def test_op_config(mocker, os_expanduser):
32 mocker.patch("os.path.exists", side_effect=[False, True])
33 op_config = OnePasswordConfig()
34
35 assert op_config.config_file_path == "/home/testuser/.config/op/config"
36
37
38 def test_op_no_config(mocker, os_expanduser):
39 mocker.patch("os.path.exists", return_value=False)
40 op_config = OnePasswordConfig()
41
42 assert op_config.config_file_path is None