Skip to content

Commit

Permalink
Propagate client's adapter to api categories (#939)
Browse files Browse the repository at this point in the history
  • Loading branch information
WilkenSteiner committed Jan 29, 2023
1 parent ee0a9e6 commit 9fedf49
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
6 changes: 0 additions & 6 deletions hvac/api/system_backend/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,3 @@ class SystemBackend(
Wrapping,
]
unimplemented_classes = []

def __init__(self, adapter):
self._adapter = adapter

def __getattr__(self, item):
raise AttributeError
6 changes: 5 additions & 1 deletion hvac/v1/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def __init__(
:param session: Optional session object to use when performing request.
:type session: request.Session
:param adapter: Optional class to be used for performing requests. If none is provided, defaults to
hvac.adapters.JSONRequest
hvac.adapters.JSONRequest.
:type adapter: hvac.adapters.Adapter
:param kwargs: Additional parameters to pass to the adapter constructor.
:type kwargs: dict
Expand Down Expand Up @@ -115,11 +115,15 @@ def __getattr__(self, name):

@property
def adapter(self):
"""Adapter for all client's connections."""
return self._adapter

@adapter.setter
def adapter(self, adapter):
self._adapter = adapter
self._auth.adapter = adapter
self._secrets.adapter = adapter
self._sys.adapter = adapter

@property
def url(self):
Expand Down
20 changes: 20 additions & 0 deletions tests/unit_tests/v1/test_client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from unittest import TestCase

from hvac import Client
from hvac.adapters import JSONAdapter


class TestClient(TestCase):
"""Unit tests providing coverage for client related methods."""

def test_setting_adapter_on_client_sets_adapter_of_endpoint_classes(self):
client = Client()
old_adapter = client.adapter

client.adapter = JSONAdapter()

self.assertIsNot(client.adapter, old_adapter)
self.assertSetEqual(
{client.adapter},
{client.secrets.adapter, client.sys.adapter, client.auth.adapter},
)

0 comments on commit 9fedf49

Please sign in to comment.