mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-28 23:51:23 -07:00
Add onepassword_doc lookup plugin (#7490)
* Add onepassword_doc lookup plugin * Switch to a doc fragment * Add unit test * Update docs * Move parameter validation to the OnePass object This makes it built in for other lookup plugins using this class. * Use kwargs for OnePass instantiation There are enough parameters now that using them positionally can result in odd behavior. * Update tests Correct conftest file name so fixtures are discovered and loaded correctly Move constant so it doesn’t need to be imported Add a patch since the parameter validation moved to part of the class init * Use a lookup docs fragment * Correct plugin description
This commit is contained in:
parent
5adb7ab948
commit
e0346d400f
6 changed files with 256 additions and 137 deletions
|
@ -10,17 +10,11 @@ import pytest
|
|||
from ansible_collections.community.general.plugins.lookup.onepassword import OnePass
|
||||
|
||||
|
||||
OP_VERSION_FIXTURES = [
|
||||
"opv1",
|
||||
"opv2"
|
||||
]
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def fake_op(mocker):
|
||||
def _fake_op(version):
|
||||
mocker.patch("ansible_collections.community.general.plugins.lookup.onepassword.OnePassCLIBase.get_current_version", return_value=version)
|
||||
op = OnePass(None, None, None, None, None)
|
||||
op = OnePass()
|
||||
op._config._config_file_path = "/home/jin/.op/config"
|
||||
mocker.patch.object(op._cli, "_run")
|
||||
|
|
@ -10,12 +10,6 @@ import itertools
|
|||
import json
|
||||
import pytest
|
||||
|
||||
from .onepassword_conftest import ( # noqa: F401, pylint: disable=unused-import
|
||||
OP_VERSION_FIXTURES,
|
||||
fake_op,
|
||||
opv1,
|
||||
opv2,
|
||||
)
|
||||
from .onepassword_common import MOCK_ENTRIES
|
||||
|
||||
from ansible.errors import AnsibleLookupError, AnsibleOptionsError
|
||||
|
@ -26,6 +20,12 @@ from ansible_collections.community.general.plugins.lookup.onepassword import (
|
|||
)
|
||||
|
||||
|
||||
OP_VERSION_FIXTURES = [
|
||||
"opv1",
|
||||
"opv2"
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("args", "rc", "expected_call_args", "expected_call_kwargs", "expected"),
|
||||
(
|
||||
|
@ -270,10 +270,21 @@ def test_signin(op_fixture, request):
|
|||
op = request.getfixturevalue(op_fixture)
|
||||
op._cli.master_password = "master_pass"
|
||||
op._cli.signin()
|
||||
print(op._cli.version)
|
||||
op._cli._run.assert_called_once_with(['signin', '--raw'], command_input=b"master_pass")
|
||||
|
||||
|
||||
def test_op_doc(mocker):
|
||||
document_contents = "Document Contents\n"
|
||||
|
||||
mocker.patch("ansible_collections.community.general.plugins.lookup.onepassword.OnePass.assert_logged_in", return_value=True)
|
||||
mocker.patch("ansible_collections.community.general.plugins.lookup.onepassword.OnePassCLIBase._run", return_value=(0, document_contents, ""))
|
||||
|
||||
op_lookup = lookup_loader.get("community.general.onepassword_doc")
|
||||
result = op_lookup.run(["Private key doc"])
|
||||
|
||||
assert result == [document_contents]
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("plugin", "connect_host", "connect_token"),
|
||||
[
|
||||
|
@ -286,8 +297,11 @@ def test_signin(op_fixture, request):
|
|||
)
|
||||
]
|
||||
)
|
||||
def test_op_connect_partial_args(plugin, connect_host, connect_token):
|
||||
def test_op_connect_partial_args(plugin, connect_host, connect_token, mocker):
|
||||
op_lookup = lookup_loader.get(plugin)
|
||||
|
||||
mocker.patch("ansible_collections.community.general.plugins.lookup.onepassword.OnePass._get_cli_class", OnePassCLIv2)
|
||||
|
||||
with pytest.raises(AnsibleOptionsError):
|
||||
op_lookup.run("login", vault_name="test vault", connect_host=connect_host, connect_token=connect_token)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue