-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Consolidate onepassword unit tests so that ansible-test will find the…
…m when the plugin is modified (#6075) Consolidate onepassword unit tests so that ansible-test will find them when the plugin is modified.
- Loading branch information
1 parent
b72b7d4
commit de1f0ff
Showing
18 changed files
with
89 additions
and
106 deletions.
There are no files selected for viewing
Empty file.
50 changes: 0 additions & 50 deletions
50
tests/unit/plugins/lookup/onepassword/test_onepassword_cli_v1.py
This file was deleted.
Oops, something went wrong.
52 changes: 0 additions & 52 deletions
52
tests/unit/plugins/lookup/onepassword/test_onepassword_cli_v2.py
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# Copyright (c) 2020 Ansible Project | ||
# Copyright (c) 2022 Ansible Project | ||
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt) | ||
# SPDX-License-Identifier: GPL-3.0-or-later | ||
|
||
|
@@ -10,8 +10,13 @@ | |
import json | ||
import pytest | ||
|
||
from .conftest import OP_VERSION_FIXTURES | ||
from .common import MOCK_ENTRIES | ||
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 | ||
from ansible.plugins.loader import lookup_loader | ||
|
@@ -21,6 +26,86 @@ | |
) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
("args", "rc", "expected_call_args", "expected_call_kwargs", "expected"), | ||
( | ||
([], 0, ["get", "account"], {"ignore_errors": True}, True,), | ||
([], 1, ["get", "account"], {"ignore_errors": True}, False,), | ||
(["acme"], 1, ["get", "account", "--account", "acme.1password.com"], {"ignore_errors": True}, False,), | ||
) | ||
) | ||
def test_assert_logged_in_v1(mocker, args, rc, expected_call_args, expected_call_kwargs, expected): | ||
mocker.patch.object(OnePassCLIv1, "_run", return_value=[rc, "", ""]) | ||
|
||
op_cli = OnePassCLIv1(*args) | ||
result = op_cli.assert_logged_in() | ||
|
||
op_cli._run.assert_called_with(expected_call_args, **expected_call_kwargs) | ||
assert result == expected | ||
|
||
|
||
def test_full_signin_v1(mocker): | ||
mocker.patch.object(OnePassCLIv1, "_run", return_value=[0, "", ""]) | ||
|
||
op_cli = OnePassCLIv1( | ||
subdomain="acme", | ||
username="[email protected]", | ||
secret_key="SECRET", | ||
master_password="ONEKEYTORULETHEMALL", | ||
) | ||
result = op_cli.full_signin() | ||
|
||
op_cli._run.assert_called_with([ | ||
"signin", | ||
"acme.1password.com", | ||
b"[email protected]", | ||
b"SECRET", | ||
"--raw", | ||
], command_input=b"ONEKEYTORULETHEMALL") | ||
assert result == [0, "", ""] | ||
|
||
|
||
@pytest.mark.parametrize( | ||
("args", "out", "expected_call_args", "expected_call_kwargs", "expected"), | ||
( | ||
([], "list of accounts", ["account", "get"], {"ignore_errors": True}, True,), | ||
(["acme"], "list of accounts", ["account", "get", "--account", "acme.1password.com"], {"ignore_errors": True}, True,), | ||
([], "", ["account", "list"], {}, False,), | ||
) | ||
) | ||
def test_assert_logged_in_v2(mocker, args, out, expected_call_args, expected_call_kwargs, expected): | ||
mocker.patch.object(OnePassCLIv2, "_run", return_value=[0, out, ""]) | ||
op_cli = OnePassCLIv2(*args) | ||
result = op_cli.assert_logged_in() | ||
|
||
op_cli._run.assert_called_with(expected_call_args, **expected_call_kwargs) | ||
assert result == expected | ||
|
||
|
||
def test_full_signin_v2(mocker): | ||
mocker.patch.object(OnePassCLIv2, "_run", return_value=[0, "", ""]) | ||
|
||
op_cli = OnePassCLIv2( | ||
subdomain="acme", | ||
username="[email protected]", | ||
secret_key="SECRET", | ||
master_password="ONEKEYTORULETHEMALL", | ||
) | ||
result = op_cli.full_signin() | ||
|
||
op_cli._run.assert_called_with( | ||
[ | ||
"account", "add", "--raw", | ||
"--address", "acme.1password.com", | ||
"--email", b"[email protected]", | ||
"--signin", | ||
], | ||
command_input=b"ONEKEYTORULETHEMALL", | ||
environment_update={'OP_SECRET_KEY': 'SECRET'}, | ||
) | ||
assert result == [0, "", ""] | ||
|
||
|
||
@pytest.mark.parametrize( | ||
("version", "version_class"), | ||
( | ||
|