Skip to content

Commit e46cc97

Browse files
committed
Add integration tests for the graph client
1 parent 4b55db6 commit e46cc97

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import pytest
2+
from requests import Session
3+
4+
from msgraphcore.enums import APIVersion
5+
from msgraphcore.graph_client import GraphClient
6+
from msgraphcore.middleware.authorization import AuthorizationHandler
7+
8+
9+
class _CustomTokenCredential:
10+
def get_token(self, scopes):
11+
return ['{token:https://graph.microsoft.com/}']
12+
13+
14+
def test_graph_client_with_default_middleware():
15+
"""
16+
Test that a graph client uses default middleware if none are provided
17+
"""
18+
credential = _CustomTokenCredential()
19+
client = GraphClient(credential=credential)
20+
response = client.get(
21+
'https://proxy.apisandbox.msdn.microsoft.com/svc?url=https://graph.microsoft.com/v1.0/me'
22+
)
23+
assert response.status_code == 200
24+
25+
26+
def test_graph_client_with_user_provided_session():
27+
"""
28+
Test that the graph client works with a user provided session object
29+
"""
30+
31+
session = Session()
32+
credential = _CustomTokenCredential()
33+
client = GraphClient(session=session, credential=credential)
34+
response = client.get(
35+
'https://proxy.apisandbox.msdn.microsoft.com/svc?url=https://graph.microsoft.com/v1.0/me'
36+
)
37+
assert response.status_code == 200
38+
39+
40+
def test_graph_client_with_custom_settings():
41+
"""
42+
Test that the graph client works with user provided configuration
43+
"""
44+
credential = _CustomTokenCredential()
45+
client = GraphClient(api_version=APIVersion.beta, credential=credential)
46+
response = client.get(
47+
'https://proxy.apisandbox.msdn.microsoft.com/svc?url=https://graph.microsoft.com/v1.0/me'
48+
)
49+
assert response.status_code == 200
50+
51+
52+
def test_client_factory_with_custom_middleware():
53+
"""
54+
Test client factory works with user provided middleware
55+
"""
56+
credential = _CustomTokenCredential()
57+
middleware = [
58+
AuthorizationHandler(credential),
59+
]
60+
client = GraphClient(middleware=middleware)
61+
response = client.get(
62+
'https://proxy.apisandbox.msdn.microsoft.com/svc?url=https://graph.microsoft.com/v1.0/me'
63+
)
64+
assert response.status_code == 200

0 commit comments

Comments
 (0)