1
1
import pytest
2
+ from httpx import ASGITransport
2
3
from authlib .integrations .httpx_client import (
3
4
OAuthError ,
4
5
AsyncOAuth1Client ,
@@ -19,8 +20,8 @@ async def assert_func(request):
19
20
assert 'oauth_consumer_key="id"' in auth_header
20
21
assert 'oauth_signature=' in auth_header
21
22
22
- app = AsyncMockDispatch (request_token , assert_func = assert_func )
23
- async with AsyncOAuth1Client ('id' , 'secret' , app = app ) as client :
23
+ transport = ASGITransport ( AsyncMockDispatch (request_token , assert_func = assert_func ) )
24
+ async with AsyncOAuth1Client ('id' , 'secret' , transport = transport ) as client :
24
25
response = await client .fetch_request_token (oauth_url )
25
26
26
27
assert response == request_token
@@ -38,11 +39,11 @@ async def assert_func(request):
38
39
assert b'oauth_consumer_key=id' in content
39
40
assert b'&oauth_signature=' in content
40
41
41
- mock_response = AsyncMockDispatch (request_token , assert_func = assert_func )
42
+ transport = ASGITransport ( AsyncMockDispatch (request_token , assert_func = assert_func ) )
42
43
43
44
async with AsyncOAuth1Client (
44
45
'id' , 'secret' , signature_type = SIGNATURE_TYPE_BODY ,
45
- app = mock_response ,
46
+ transport = transport ,
46
47
) as client :
47
48
response = await client .fetch_request_token (oauth_url )
48
49
@@ -61,11 +62,11 @@ async def assert_func(request):
61
62
assert 'oauth_consumer_key=id' in url
62
63
assert '&oauth_signature=' in url
63
64
64
- mock_response = AsyncMockDispatch (request_token , assert_func = assert_func )
65
+ transport = ASGITransport ( AsyncMockDispatch (request_token , assert_func = assert_func ) )
65
66
66
67
async with AsyncOAuth1Client (
67
68
'id' , 'secret' , signature_type = SIGNATURE_TYPE_QUERY ,
68
- app = mock_response ,
69
+ transport = transport ,
69
70
) as client :
70
71
response = await client .fetch_request_token (oauth_url )
71
72
@@ -83,10 +84,10 @@ async def assert_func(request):
83
84
assert 'oauth_consumer_key="id"' in auth_header
84
85
assert 'oauth_signature=' in auth_header
85
86
86
- mock_response = AsyncMockDispatch (request_token , assert_func = assert_func )
87
+ transport = ASGITransport ( AsyncMockDispatch (request_token , assert_func = assert_func ) )
87
88
async with AsyncOAuth1Client (
88
89
'id' , 'secret' , token = 'foo' , token_secret = 'bar' ,
89
- app = mock_response ,
90
+ transport = transport ,
90
91
) as client :
91
92
with pytest .raises (OAuthError ):
92
93
await client .fetch_access_token (oauth_url )
@@ -98,10 +99,10 @@ async def assert_func(request):
98
99
99
100
@pytest .mark .asyncio
100
101
async def test_get_via_header ():
101
- mock_response = AsyncMockDispatch (b'hello' )
102
+ transport = ASGITransport ( AsyncMockDispatch (b'hello' ) )
102
103
async with AsyncOAuth1Client (
103
104
'id' , 'secret' , token = 'foo' , token_secret = 'bar' ,
104
- app = mock_response ,
105
+ transport = transport ,
105
106
) as client :
106
107
response = await client .get ('https://example.com/' )
107
108
@@ -121,11 +122,11 @@ async def assert_func(request):
121
122
assert b'oauth_consumer_key=id' in content
122
123
assert b'oauth_signature=' in content
123
124
124
- mock_response = AsyncMockDispatch (b'hello' , assert_func = assert_func )
125
+ transport = ASGITransport ( AsyncMockDispatch (b'hello' , assert_func = assert_func ) )
125
126
async with AsyncOAuth1Client (
126
127
'id' , 'secret' , token = 'foo' , token_secret = 'bar' ,
127
128
signature_type = SIGNATURE_TYPE_BODY ,
128
- app = mock_response ,
129
+ transport = transport ,
129
130
) as client :
130
131
response = await client .post ('https://example.com/' )
131
132
@@ -138,11 +139,11 @@ async def assert_func(request):
138
139
139
140
@pytest .mark .asyncio
140
141
async def test_get_via_query ():
141
- mock_response = AsyncMockDispatch (b'hello' )
142
+ transport = ASGITransport ( AsyncMockDispatch (b'hello' ) )
142
143
async with AsyncOAuth1Client (
143
144
'id' , 'secret' , token = 'foo' , token_secret = 'bar' ,
144
145
signature_type = SIGNATURE_TYPE_QUERY ,
145
- app = mock_response ,
146
+ transport = transport ,
146
147
) as client :
147
148
response = await client .get ('https://example.com/' )
148
149
0 commit comments