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 1 commit
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
6 changes: 5 additions & 1 deletion msgraphcore/graph_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ class GraphSession(Session):
"""
def __init__(self, auth_provider: AuthProviderBase, middleware: list = []):
super().__init__()
self.headers.update({'sdkVersion': 'graph-python-' + SDK_VERSION})
if 'sdkVersion' not in self.headers:
self.headers.update({'sdkVersion': 'graph-python-' + SDK_VERSION})
else:
self.headers.update({'sdkVersion': 'graph-python-' + SDK_VERSION + ', '
+ self.headers.get('sdkVersion')})
Copy link
Contributor

@jobala jobala Apr 29, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put this functionality in a private method _append_sdk_version and call the function in the constructor.

I prefer checking if sdkVersion is in headers first

if 'sdkVersion' in self.headers:
   ...
else:
  ...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure I'll make the changes!

self._base_url = BASE_URL

auth_handler = AuthorizationHandler(auth_provider)
Expand Down
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