Skip to content

Update sdkVersion in graph_session.py #46

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion msgraphcore/graph_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class GraphSession(Session):
"""
def __init__(self, auth_provider: AuthProviderBase, middleware: list = []):
super().__init__()
self.headers.update({'sdkVersion': 'graph-python-' + SDK_VERSION})
self._append_sdk_version()
self._base_url = BASE_URL

auth_handler = AuthorizationHandler(auth_provider)
Expand Down Expand Up @@ -106,3 +106,12 @@ def _register(self, middleware: [BaseMiddleware]) -> None:
middleware_pipeline.add_middleware(ware)

self.mount('https://', middleware_pipeline)

def _append_sdk_version(self) -> None:
"""Updates sdkVersion in headers with comma-separated new values
"""
if 'sdkVersion' in self.headers:
self.headers.update({'sdkVersion': 'graph-python-' + SDK_VERSION + ', '
+ self.headers.get('sdkVersion')})
else:
self.headers.update({'sdkVersion': 'graph-python-' + SDK_VERSION})
6 changes: 5 additions & 1 deletion tests/unit/test_graph_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ def test_has_graph_url_as_base_url(self):
self.assertEqual(self.requests._base_url, BASE_URL)

def test_has_sdk_version_header(self):
self.assertEqual(self.requests.headers.get('sdkVersion'), 'graph-python-'+SDK_VERSION)
self.assertTrue('sdkVersion' in self.requests.headers)

def test_updated_sdk_version(self):
self.assertTrue(self.requests.headers.get('sdkVersion')
.startswith('graph-python-'+SDK_VERSION))

def test_initialized_with_middlewares(self):
graph_session = GraphSession(self.auth_provider)
Expand Down