def test_explicit_version(mocker, test_input, version_override): """check that the secret version is overridden when explicit version is provided to vault jinja2 filter""" mocker.patch.object(VaultClient, "defaultClient") mocked_VaultSecret = mocker.MagicMock() mocker.patch("as3ninja.vault.VaultSecret", return_value=mocked_VaultSecret) vault(ctx=MockContext(), secret=test_input, version=version_override) assert mocked_VaultSecret.version == version_override
def test_expected_filters(mocker, test_secret, expected_filter): """check that the filter for kv1 and kv2 are applied correctly. kv2 should have data.data.key as a result as data. is prepended automatically.""" mocker.patch.object(VaultClient, "Client") mocked_dict_filter = mocker.patch("as3ninja.vault.dict_filter") vault(ctx=MockContext(), secret=test_secret, client=VaultClient) assert mocked_dict_filter.call_args.kwargs == { "filter": expected_filter }
def test_filter_override(mocker, test_secret, filter_overridden, expected_filter): """test that a manually specified filter overrides the filter in the secret definition""" mocker.patch.object(VaultClient, "Client") mocked_dict_filter = mocker.patch("as3ninja.vault.dict_filter") vault( ctx=MockContext(), secret=test_secret, client=VaultClient, filter=filter_overridden, ) assert mocked_dict_filter.call_args.kwargs == { "filter": expected_filter }
def test_expected_client_calls(mocker, test_input, expected_call): """check for expected calls to defaultClient""" mocker.patch.object(VaultClient, "Client") vault(ctx=MockContext(), secret=test_input, client=VaultClient) # print(VaultClient.Client.mock_calls) VaultClient.Client.assert_has_calls(expected_call)