Skip to content

Commit c7e2d9f

Browse files
committed
fix(httpx): update test cases for httpx
1 parent ce1405d commit c7e2d9f

8 files changed

+137
-129
lines changed

authlib/integrations/httpx_client/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
__all__ = [
1919
'OAuthError',
20-
'OAuth1Auth', 'AsyncOAuth1Client',
20+
'OAuth1Auth', 'AsyncOAuth1Client', 'OAuth1Client',
2121
'SIGNATURE_HMAC_SHA1', 'SIGNATURE_RSA_SHA1', 'SIGNATURE_PLAINTEXT',
2222
'SIGNATURE_TYPE_HEADER', 'SIGNATURE_TYPE_QUERY', 'SIGNATURE_TYPE_BODY',
2323
'OAuth2Auth', 'OAuth2ClientAuth', 'OAuth2Client', 'AsyncOAuth2Client',

tests/clients/test_httpx/test_assertion_client.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import time
22
import pytest
3+
from httpx import WSGITransport
34
from authlib.integrations.httpx_client import AssertionClient
45
from ..wsgi_helper import MockDispatch
56

@@ -26,7 +27,7 @@ def verifier(request):
2627
audience='foo',
2728
alg='HS256',
2829
key='secret',
29-
app=MockDispatch(default_token, assert_func=verifier)
30+
transport=WSGITransport(MockDispatch(default_token, assert_func=verifier)),
3031
) as client:
3132
client.get('https://i.b')
3233

@@ -43,7 +44,7 @@ def verifier(request):
4344
key='secret',
4445
scope='email',
4546
claims={'test_mode': 'true'},
46-
app=MockDispatch(default_token, assert_func=verifier)
47+
transport=WSGITransport(MockDispatch(default_token, assert_func=verifier)),
4748
) as client:
4849
client.get('https://i.b')
4950
client.get('https://i.b')
@@ -56,7 +57,7 @@ def test_without_alg():
5657
subject='foo',
5758
audience='foo',
5859
key='secret',
59-
app=MockDispatch(default_token)
60+
transport=WSGITransport(MockDispatch(default_token)),
6061
) as client:
6162
with pytest.raises(ValueError):
6263
client.get('https://i.b')

tests/clients/test_httpx/test_async_assertion_client.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import time
22
import pytest
3+
from httpx import ASGITransport
34
from authlib.integrations.httpx_client import AsyncAssertionClient
45
from ..asgi_helper import AsyncMockDispatch
56

@@ -28,7 +29,7 @@ async def verifier(request):
2829
audience='foo',
2930
alg='HS256',
3031
key='secret',
31-
app=AsyncMockDispatch(default_token, assert_func=verifier)
32+
transport=ASGITransport(AsyncMockDispatch(default_token, assert_func=verifier)),
3233
) as client:
3334
await client.get('https://i.b')
3435

@@ -45,7 +46,7 @@ async def verifier(request):
4546
key='secret',
4647
scope='email',
4748
claims={'test_mode': 'true'},
48-
app=AsyncMockDispatch(default_token, assert_func=verifier)
49+
transport=ASGITransport(AsyncMockDispatch(default_token, assert_func=verifier)),
4950
) as client:
5051
await client.get('https://i.b')
5152
await client.get('https://i.b')
@@ -59,7 +60,7 @@ async def test_without_alg():
5960
subject='foo',
6061
audience='foo',
6162
key='secret',
62-
app=AsyncMockDispatch()
63+
transport=ASGITransport(AsyncMockDispatch()),
6364
) as client:
6465
with pytest.raises(ValueError):
6566
await client.get('https://i.b')

tests/clients/test_httpx/test_async_oauth1_client.py

+15-14
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import pytest
2+
from httpx import ASGITransport
23
from authlib.integrations.httpx_client import (
34
OAuthError,
45
AsyncOAuth1Client,
@@ -19,8 +20,8 @@ async def assert_func(request):
1920
assert 'oauth_consumer_key="id"' in auth_header
2021
assert 'oauth_signature=' in auth_header
2122

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:
2425
response = await client.fetch_request_token(oauth_url)
2526

2627
assert response == request_token
@@ -38,11 +39,11 @@ async def assert_func(request):
3839
assert b'oauth_consumer_key=id' in content
3940
assert b'&oauth_signature=' in content
4041

41-
mock_response = AsyncMockDispatch(request_token, assert_func=assert_func)
42+
transport = ASGITransport(AsyncMockDispatch(request_token, assert_func=assert_func))
4243

4344
async with AsyncOAuth1Client(
4445
'id', 'secret', signature_type=SIGNATURE_TYPE_BODY,
45-
app=mock_response,
46+
transport=transport,
4647
) as client:
4748
response = await client.fetch_request_token(oauth_url)
4849

@@ -61,11 +62,11 @@ async def assert_func(request):
6162
assert 'oauth_consumer_key=id' in url
6263
assert '&oauth_signature=' in url
6364

64-
mock_response = AsyncMockDispatch(request_token, assert_func=assert_func)
65+
transport = ASGITransport(AsyncMockDispatch(request_token, assert_func=assert_func))
6566

6667
async with AsyncOAuth1Client(
6768
'id', 'secret', signature_type=SIGNATURE_TYPE_QUERY,
68-
app=mock_response,
69+
transport=transport,
6970
) as client:
7071
response = await client.fetch_request_token(oauth_url)
7172

@@ -83,10 +84,10 @@ async def assert_func(request):
8384
assert 'oauth_consumer_key="id"' in auth_header
8485
assert 'oauth_signature=' in auth_header
8586

86-
mock_response = AsyncMockDispatch(request_token, assert_func=assert_func)
87+
transport = ASGITransport(AsyncMockDispatch(request_token, assert_func=assert_func))
8788
async with AsyncOAuth1Client(
8889
'id', 'secret', token='foo', token_secret='bar',
89-
app=mock_response,
90+
transport=transport,
9091
) as client:
9192
with pytest.raises(OAuthError):
9293
await client.fetch_access_token(oauth_url)
@@ -98,10 +99,10 @@ async def assert_func(request):
9899

99100
@pytest.mark.asyncio
100101
async def test_get_via_header():
101-
mock_response = AsyncMockDispatch(b'hello')
102+
transport = ASGITransport(AsyncMockDispatch(b'hello'))
102103
async with AsyncOAuth1Client(
103104
'id', 'secret', token='foo', token_secret='bar',
104-
app=mock_response,
105+
transport=transport,
105106
) as client:
106107
response = await client.get('https://example.com/')
107108

@@ -121,11 +122,11 @@ async def assert_func(request):
121122
assert b'oauth_consumer_key=id' in content
122123
assert b'oauth_signature=' in content
123124

124-
mock_response = AsyncMockDispatch(b'hello', assert_func=assert_func)
125+
transport = ASGITransport(AsyncMockDispatch(b'hello', assert_func=assert_func))
125126
async with AsyncOAuth1Client(
126127
'id', 'secret', token='foo', token_secret='bar',
127128
signature_type=SIGNATURE_TYPE_BODY,
128-
app=mock_response,
129+
transport=transport,
129130
) as client:
130131
response = await client.post('https://example.com/')
131132

@@ -138,11 +139,11 @@ async def assert_func(request):
138139

139140
@pytest.mark.asyncio
140141
async def test_get_via_query():
141-
mock_response = AsyncMockDispatch(b'hello')
142+
transport = ASGITransport(AsyncMockDispatch(b'hello'))
142143
async with AsyncOAuth1Client(
143144
'id', 'secret', token='foo', token_secret='bar',
144145
signature_type=SIGNATURE_TYPE_QUERY,
145-
app=mock_response,
146+
transport=transport,
146147
) as client:
147148
response = await client.get('https://example.com/')
148149

0 commit comments

Comments
 (0)