Skip to content

Commit cdef942

Browse files
committed
Update tests
1 parent 6fbce8a commit cdef942

File tree

4 files changed

+28
-9
lines changed

4 files changed

+28
-9
lines changed

msgraphcore/middleware/authorization.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from ._base_auth import AuthProviderBase, TokenCredential
2-
from ..constants import AUTH_MIDDLEWARE_OPTIONS
2+
from ..constants import AUTH_MIDDLEWARE_OPTIONS, BASE_URL
33
from ._middleware import BaseMiddleware
44

55

@@ -29,9 +29,25 @@ def _get_middleware_options(self, request):
2929

3030

3131
class TokenCredentialAuthProvider(AuthProviderBase):
32-
def __init__(self, scopes: str, credential: TokenCredential):
32+
def __init__(self, credential: TokenCredential, scopes: [str] = BASE_URL + '.default'):
3333
self.credential = credential
3434
self.scopes = scopes
3535

36+
@property
37+
def scopes(self):
38+
return self._scopes
39+
40+
@scopes.setter
41+
def scopes(self, list_of_scopes):
42+
if type(list_of_scopes) == list:
43+
graph_scopes = BASE_URL + '?scopes='
44+
45+
for scope in list_of_scopes:
46+
graph_scopes += scope + '%20'
47+
48+
self._scopes = graph_scopes
49+
elif type(list_of_scopes) == str:
50+
self._scopes = list_of_scopes
51+
3652
def get_access_token(self):
3753
return self.credential.get_token(self.scopes)[0]

tests/integration/test_middleware_pipeline.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,17 @@ def setUp(self):
1111

1212
def test_middleware_pipeline(self):
1313
url = 'https://proxy.apisandbox.msdn.microsoft.com/svc?url=https://graph.microsoft.com/v1.0/me'
14-
15-
auth_provider = _CustomAuthProvider()
1614
scopes = ['user.read']
17-
graph_session = GraphSession(scopes, auth_provider)
15+
auth_provider = _CustomAuthProvider(scopes)
16+
graph_session = GraphSession(auth_provider)
1817
result = graph_session.get(url)
1918

2019
self.assertEqual(result.status_code, 200)
2120

2221

2322
class _CustomAuthProvider(AuthProviderBase):
23+
def __init__(self, scopes):
24+
pass
2425

2526
def get_access_token(self):
2627
return '{token:https://graph.microsoft.com/}'

tests/unit/test_graph_session.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111

1212
class GraphSessionTest(TestCase):
1313
def setUp(self) -> None:
14-
self.auth_provider = _CustomAuthProvider()
15-
self.requests = GraphSession(['user.read'], self.auth_provider)
14+
self.auth_provider = _CustomAuthProvider(['user.read'])
15+
self.requests = GraphSession(self.auth_provider)
1616

1717
def tearDown(self) -> None:
1818
self.requests = None
@@ -27,7 +27,7 @@ def test_has_sdk_version_header(self):
2727
self.assertEqual(self.requests.headers.get('sdkVersion'), 'graph-python-'+SDK_VERSION)
2828

2929
def test_initialized_with_middlewares(self):
30-
graph_session = GraphSession(['user.read'], self.auth_provider)
30+
graph_session = GraphSession(self.auth_provider)
3131
mocked_middleware = graph_session.get_adapter('https://')
3232

3333
self.assertIsInstance(mocked_middleware, HTTPAdapter)
@@ -54,6 +54,8 @@ def test_does_not_build_graph_urls_for_full_urls(self):
5454

5555

5656
class _CustomAuthProvider(AuthProviderBase):
57+
def __init__(self, scopes):
58+
pass
5759

5860
def get_access_token(self):
5961
return '{token:https://graph.microsoft.com/}'

tests/unit/test_middleware_options.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66
class TestMiddlewareOptions(TestCase):
77
def test_multiple_scopes(self):
88
graph_scopes = 'https://graph.microsoft.com/v1.0?scopes=mail.read%20user.read%20'
9-
auth_options = AuthMiddlewareOptions(scopes=['mail.read', 'user.read'])
9+
auth_options = AuthMiddlewareOptions(graph_scopes)
1010
self.assertEqual(auth_options.scopes, graph_scopes)

0 commit comments

Comments
 (0)