def test_Client_return_value(mocker): """test Client() returns self._client""" mocked_Client = mocker.patch("as3ninja.vault.hvac.Client") vc = VaultClient(addr="http://localhost:18200", token="123", verify=False) mocked_vc__client = mocker.patch.object(vc, "_client") mocked_Client.assert_called_with(url="http://localhost:18200", verify=False) assert vc.Client() == mocked_vc__client
def test_existing_defaultClient(mocker, monkeypatch): """check that hvac.Client is not called when self._defaultClient is not None""" mocker.patch("as3ninja.vault.hvac.Client") monkeypatch.setattr(VaultClient, "_defaultClient", hvac.v1.Client()) vc = VaultClient.defaultClient(ctx=MockContext({})) assert isinstance(vc, hvac.v1.Client) assert hvac.Client.called == False
def test_interface(mocker): mocked_Client = mocker.patch("as3ninja.vault.hvac.Client") vc = VaultClient(addr="http://localhost:18200", token="123", verify=False) mocked_Client.assert_called_with(url="http://localhost:18200", verify=False) assert vc._client.token == "123"
def _func(mocker, monkeypatch, v_ctx): mocker.patch("as3ninja.vault.hvac.Client", autospec=True) hvac.Client.return_value = Mock_hvacClient() monkeypatch.setattr(VaultClient, "_defaultClient", False) return VaultClient.defaultClient(ctx=MockContext(v_ctx))
def test_not_authenticated(monkeypatch): monkeypatch.setattr(hvac.Client, "is_authenticated", lambda _: False) with pytest.raises(hvac.exceptions.VaultError): VaultClient.defaultClient(ctx=MockContext())
def test_not_authenticated(monkeypatch): monkeypatch.setattr(hvac.Client, "is_authenticated", lambda _: False) with pytest.raises(hvac.exceptions.VaultError): VaultClient(addr="http://localhost:18200", token="123")
def test_is_authenticated(mocker): mocked_Client = mocker.patch("as3ninja.vault.hvac.Client") assert VaultClient(addr="http://localhost:18200", token="123") mocked_Client.assert_called_with(url="http://localhost:18200", verify=True)