Skip to content

Commit a199bda

Browse files
committed
Merge remote-tracking branch 'origin/task/refactor-graph-session' into task/refactor-graph-session
2 parents db67357 + 22f90de commit a199bda

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

msgraphcore/graph_session.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def __init__(self,
2121
middleware: list = []
2222
):
2323
super().__init__()
24-
self.headers.update({'sdkVersion': 'graph-python-' + SDK_VERSION})
24+
self._append_sdk_version()
2525
self._base_url = BASE_URL
2626

2727
auth_handler = AuthorizationHandler(credential, scopes)
@@ -107,3 +107,12 @@ def _register(self, middleware: [BaseMiddleware]) -> None:
107107
middleware_pipeline.add_middleware(ware)
108108

109109
self.mount('https://', middleware_pipeline)
110+
111+
def _append_sdk_version(self) -> None:
112+
"""Updates sdkVersion in headers with comma-separated new values
113+
"""
114+
if 'sdkVersion' in self.headers:
115+
self.headers.update({'sdkVersion': 'graph-python-' + SDK_VERSION + ', '
116+
+ self.headers.get('sdkVersion')})
117+
else:
118+
self.headers.update({'sdkVersion': 'graph-python-' + SDK_VERSION})

tests/unit/test_graph_session.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@ def test_has_graph_url_as_base_url(self):
2323
self.assertEqual(self.requests._base_url, BASE_URL)
2424

2525
def test_has_sdk_version_header(self):
26-
self.assertEqual(self.requests.headers.get('sdkVersion'), 'graph-python-'+SDK_VERSION)
26+
self.assertTrue('sdkVersion' in self.requests.headers)
27+
28+
def test_updated_sdk_version(self):
29+
self.assertTrue(self.requests.headers.get('sdkVersion')
30+
.startswith('graph-python-'+SDK_VERSION))
2731

2832
def test_initialized_with_middlewares(self):
2933
graph_session = GraphSession(self.credential)

0 commit comments

Comments
 (0)