Skip to content

Commit

Permalink
Merge pull request #187 from lumapps/feat/reuse-header-for-new-client
Browse files Browse the repository at this point in the history
feat(api): keep extra headers in get_new_client_as
  • Loading branch information
jssevestre committed Feb 23, 2023
2 parents 31667ac + 60d7493 commit b773a6e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lumapps/api/base_client.py
Expand Up @@ -74,8 +74,9 @@ def __init__(
self._endpoints = None
self._client = None
self._headers: dict = {"x-lumapps-analytics": "off"}
if extra_http_headers:
self._headers.update(extra_http_headers)
self._extra_http_headers = extra_http_headers
if self._extra_http_headers:
self._headers.update(self._extra_http_headers)
if api_info is None:
api_info = {}
api_info.setdefault("name", LUMAPPS_NAME)
Expand Down Expand Up @@ -231,6 +232,7 @@ def get_new_client_as_using_dwd(self, user_email: str) -> "BaseClient":
no_verify=self.no_verify,
proxy_info=self.proxy_info,
prune=self.prune,
extra_http_headers=self._extra_http_headers,
)

def get_new_client_as(
Expand All @@ -252,6 +254,7 @@ def get_new_client_as(
no_verify=self.no_verify,
proxy_info=self.proxy_info,
prune=self.prune,
extra_http_headers=self._extra_http_headers,
)
token_infos: Any = client.get_call(
"user/getToken", customerId=customer_id, email=user_email
Expand All @@ -264,6 +267,7 @@ def get_new_client_as(
no_verify=self.no_verify,
proxy_info=self.proxy_info,
prune=self.prune,
extra_http_headers=self._extra_http_headers,
)

@property
Expand Down
14 changes: 14 additions & 0 deletions tests/legacy/test_client.py
Expand Up @@ -43,3 +43,17 @@ def test_custom_headers():
headers = {"my-header": "on"}
cli = LumAppsClient("a", "b", token="FAKE", extra_http_headers=headers)
assert "my-header" in cli.client.headers


def test_custom_headers_for_new_client(mocker):
def dummy_get_call(*args, **kwargs):
return {"accessToken": "1"}
mocker.patch(
"lumapps.api.base_client.BaseClient.get_call",
dummy_get_call,
)

headers = {"my-header": "on"}
cli = LumAppsClient("a", "b", token="FAKE", extra_http_headers=headers)
new_as = cli.get_new_client_as("user_email")
assert "my-header" in new_as.client.headers

0 comments on commit b773a6e

Please sign in to comment.