Skip to content

Commit

Permalink
Drop upper version bound of pytest-aiohttp
Browse files Browse the repository at this point in the history
Use fixture `aiohttp_client` instead of `test_client`.  All the tests
back to Python 3.5 complained that `test_client` was deprecated.
  • Loading branch information
michael-k committed Nov 4, 2022
1 parent 9cee62e commit c23bb69
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 30 deletions.
52 changes: 26 additions & 26 deletions tests/ext/aiohttp/test_middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,15 +120,15 @@ def recorder(loop):
patcher.stop()


async def test_ok(test_client, loop, recorder):
async def test_ok(aiohttp_client, loop, recorder):
"""
Test a normal response
:param test_client: AioHttp test client fixture
:param aiohttp_client: AioHttp test client fixture
:param loop: Eventloop fixture
:param recorder: X-Ray recorder fixture
"""
client = await test_client(ServerTest.app(loop=loop))
client = await aiohttp_client(ServerTest.app(loop=loop))

resp = await client.get('/')
assert resp.status == 200
Expand All @@ -144,15 +144,15 @@ async def test_ok(test_client, loop, recorder):
assert response['status'] == 200


async def test_ok_x_forwarded_for(test_client, loop, recorder):
async def test_ok_x_forwarded_for(aiohttp_client, loop, recorder):
"""
Test a normal response with x_forwarded_for headers
:param test_client: AioHttp test client fixture
:param aiohttp_client: AioHttp test client fixture
:param loop: Eventloop fixture
:param recorder: X-Ray recorder fixture
"""
client = await test_client(ServerTest.app(loop=loop))
client = await aiohttp_client(ServerTest.app(loop=loop))

resp = await client.get('/', headers={'X-Forwarded-For': 'foo'})
assert resp.status == 200
Expand All @@ -162,15 +162,15 @@ async def test_ok_x_forwarded_for(test_client, loop, recorder):
assert segment.http['request']['x_forwarded_for']


async def test_ok_content_length(test_client, loop, recorder):
async def test_ok_content_length(aiohttp_client, loop, recorder):
"""
Test a normal response with content length as response header
:param test_client: AioHttp test client fixture
:param aiohttp_client: AioHttp test client fixture
:param loop: Eventloop fixture
:param recorder: X-Ray recorder fixture
"""
client = await test_client(ServerTest.app(loop=loop))
client = await aiohttp_client(ServerTest.app(loop=loop))

resp = await client.get('/?content_length=100')
assert resp.status == 200
Expand All @@ -179,15 +179,15 @@ async def test_ok_content_length(test_client, loop, recorder):
assert segment.http['response']['content_length'] == 100


async def test_error(test_client, loop, recorder):
async def test_error(aiohttp_client, loop, recorder):
"""
Test a 4XX response
:param test_client: AioHttp test client fixture
:param aiohttp_client: AioHttp test client fixture
:param loop: Eventloop fixture
:param recorder: X-Ray recorder fixture
"""
client = await test_client(ServerTest.app(loop=loop))
client = await aiohttp_client(ServerTest.app(loop=loop))

resp = await client.get('/error')
assert resp.status == 404
Expand All @@ -204,15 +204,15 @@ async def test_error(test_client, loop, recorder):
assert response['status'] == 404


async def test_exception(test_client, loop, recorder):
async def test_exception(aiohttp_client, loop, recorder):
"""
Test handling an exception
:param test_client: AioHttp test client fixture
:param aiohttp_client: AioHttp test client fixture
:param loop: Eventloop fixture
:param recorder: X-Ray recorder fixture
"""
client = await test_client(ServerTest.app(loop=loop))
client = await aiohttp_client(ServerTest.app(loop=loop))

with pytest.raises(Exception):
await client.get('/exception')
Expand All @@ -231,15 +231,15 @@ async def test_exception(test_client, loop, recorder):
assert exception.type == 'CancelledError'


async def test_unhauthorized(test_client, loop, recorder):
async def test_unhauthorized(aiohttp_client, loop, recorder):
"""
Test a 401 response
:param test_client: AioHttp test client fixture
:param aiohttp_client: AioHttp test client fixture
:param loop: Eventloop fixture
:param recorder: X-Ray recorder fixture
"""
client = await test_client(ServerTest.app(loop=loop))
client = await aiohttp_client(ServerTest.app(loop=loop))

resp = await client.get('/unauthorized')
assert resp.status == 401
Expand All @@ -256,8 +256,8 @@ async def test_unhauthorized(test_client, loop, recorder):
assert response['status'] == 401


async def test_response_trace_header(test_client, loop, recorder):
client = await test_client(ServerTest.app(loop=loop))
async def test_response_trace_header(aiohttp_client, loop, recorder):
client = await aiohttp_client(ServerTest.app(loop=loop))
resp = await client.get('/')
xray_header = resp.headers[http.XRAY_HEADER]
segment = recorder.emitter.pop()
Expand All @@ -266,15 +266,15 @@ async def test_response_trace_header(test_client, loop, recorder):
assert expected in xray_header


async def test_concurrent(test_client, loop, recorder):
async def test_concurrent(aiohttp_client, loop, recorder):
"""
Test multiple concurrent requests
:param test_client: AioHttp test client fixture
:param aiohttp_client: AioHttp test client fixture
:param loop: Eventloop fixture
:param recorder: X-Ray recorder fixture
"""
client = await test_client(ServerTest.app(loop=loop))
client = await aiohttp_client(ServerTest.app(loop=loop))

recorder.emitter = CustomStubbedEmitter()

Expand All @@ -292,16 +292,16 @@ async def get_delay():
assert len(ids) == len(set(ids))


async def test_disabled_sdk(test_client, loop, recorder):
async def test_disabled_sdk(aiohttp_client, loop, recorder):
"""
Test a normal response when the SDK is disabled.
:param test_client: AioHttp test client fixture
:param aiohttp_client: AioHttp test client fixture
:param loop: Eventloop fixture
:param recorder: X-Ray recorder fixture
"""
global_sdk_config.set_sdk_enabled(False)
client = await test_client(ServerTest.app(loop=loop))
client = await aiohttp_client(ServerTest.app(loop=loop))

resp = await client.get('/')
assert resp.status == 200
Expand Down
6 changes: 2 additions & 4 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,8 @@ deps =
ext-aiobotocore: aiobotocore >= 0.10.0
ext-aiobotocore: pytest-asyncio

ext-aiohttp: aiohttp >= 3.0.0
; Breaking change where the `test_client` fixture was renamed.
; Also, the stable version is only supported for Python 3.7+
ext-aiohttp: pytest-aiohttp < 1.0.0
ext-aiohttp: aiohttp >= 3.3.0
ext-aiohttp: pytest-aiohttp

ext-httpx: httpx >= 0.20
ext-httpx: pytest-asyncio >= 0.19
Expand Down

0 comments on commit c23bb69

Please sign in to comment.