Skip to content

Commit c9c9d2a

Browse files
committed
Add integration tests for client factory
1 parent 39862fa commit c9c9d2a

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import pytest
2+
from requests import Session
3+
4+
from msgraphcore.client_factory import HTTPClientFactory
5+
from msgraphcore.enums import APIVersion
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_client_factory_with_default_middleware():
15+
"""
16+
Test that a client created from client factory with default middleware
17+
works as expected.
18+
"""
19+
credential = _CustomTokenCredential()
20+
client = HTTPClientFactory().create_with_default_middleware(credential)
21+
response = client.get(
22+
'https://proxy.apisandbox.msdn.microsoft.com/svc?url=https://graph.microsoft.com/v1.0/me'
23+
)
24+
assert response.status_code == 200
25+
26+
27+
def test_client_factory_with_user_provided_session():
28+
"""
29+
Test that the client works with a user provided session object
30+
"""
31+
32+
session = Session()
33+
credential = _CustomTokenCredential()
34+
client = HTTPClientFactory(session=session).create_with_default_middleware(credential)
35+
response = client.get(
36+
'https://proxy.apisandbox.msdn.microsoft.com/svc?url=https://graph.microsoft.com/v1.0/me'
37+
)
38+
assert response.status_code == 200
39+
40+
41+
def test_client_factory_with_custom_settings():
42+
"""
43+
Test that the client works with user provided configuration
44+
"""
45+
credential = _CustomTokenCredential()
46+
client = HTTPClientFactory(api_version=APIVersion.beta
47+
).create_with_default_middleware(credential)
48+
response = client.get(
49+
'https://proxy.apisandbox.msdn.microsoft.com/svc?url=https://graph.microsoft.com/v1.0/me'
50+
)
51+
assert response.status_code == 200
52+
53+
54+
def test_client_factory_with_custom_middleware():
55+
"""
56+
Test client factory works with user provided middleware
57+
"""
58+
credential = _CustomTokenCredential()
59+
middleware = [
60+
AuthorizationHandler(credential),
61+
]
62+
client = HTTPClientFactory().create_with_custom_middleware(middleware)
63+
response = client.get(
64+
'https://proxy.apisandbox.msdn.microsoft.com/svc?url=https://graph.microsoft.com/v1.0/me'
65+
)
66+
assert response.status_code == 200

0 commit comments

Comments
 (0)