Skip to content

Commit 05bc021

Browse files
author
Ben Picolo
committed
Use asynctest built-in loop
1 parent 6ced258 commit 05bc021

File tree

3 files changed

+24
-20
lines changed

3 files changed

+24
-20
lines changed

kubernetes_asyncio/config/openid_test.py

+23-18
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import asyncio
12
import json
23

34
import pytest
@@ -36,14 +37,15 @@ def requestor():
3637
)
3738

3839

39-
@pytest.yield_fixture
40-
def working_client(loop, aiohttp_client):
40+
def working_client():
41+
loop = asyncio.get_running_loop()
42+
4143
app = web.Application()
4244

4345
app.router.add_get('/.well-known/openid-configuration', respond_json({'token_endpoint': '/token'}))
4446
app.router.add_post('/token', respond_json({'id-token': 'id-token-data', 'refresh-token': 'refresh-token-data'}))
4547

46-
with patch('kubernetes_asyncio.config.openid.OpenIDRequestor._client_session') as _client_session:
48+
with patch('kubernetes_asyncio.config.openid.aiohttp.ClientSession') as _client_session:
4749
client = TestClient(TestServer(app, loop=loop), loop=loop)
4850
_client_session.return_value = client
4951
loop.run_until_complete(client.start_server())
@@ -53,13 +55,13 @@ def working_client(loop, aiohttp_client):
5355
loop.run_until_complete(client.close())
5456

5557

56-
@pytest.yield_fixture
57-
def fail_well_known_client(loop, aiohttp_client):
58+
def fail_well_known_client():
59+
loop = asyncio.get_running_loop()
5860
app = web.Application()
5961

6062
app.router.add_get('/.well-known/openid-configuration', make_responder(web.Response(status=500)))
6163

62-
with patch('kubernetes_asyncio.config.openid.OpenIDRequestor._client_session') as _client_session:
64+
with patch('kubernetes_asyncio.config.openid.aiohttp.ClientSession') as _client_session:
6365
client = TestClient(TestServer(app, loop=loop), loop=loop)
6466
_client_session.return_value = client
6567
loop.run_until_complete(client.start_server())
@@ -69,8 +71,8 @@ def fail_well_known_client(loop, aiohttp_client):
6971
loop.run_until_complete(client.close())
7072

7173

72-
@pytest.yield_fixture
73-
def fail_token_request_client(loop, aiohttp_client):
74+
def fail_token_request_client():
75+
loop = asyncio.get_running_loop()
7476
app = web.Application()
7577

7678
app.router.add_get('/.well-known/openid-configuration', respond_json({'token_endpoint': '/token'}))
@@ -86,18 +88,21 @@ def fail_token_request_client(loop, aiohttp_client):
8688
loop.run_until_complete(client.close())
8789

8890

89-
async def test_refresh_token_success(requestor, working_client):
90-
resp = await requestor.refresh_token('my-refresh-token')
91+
async def test_refresh_token_success(requestor):
92+
with working_client():
93+
resp = await requestor.refresh_token('my-refresh-token')
9194

92-
assert resp['id-token'] == 'id-token-data'
93-
assert resp['refresh-token'] == 'refresh-token-data'
95+
assert resp['id-token'] == 'id-token-data'
96+
assert resp['refresh-token'] == 'refresh-token-data'
9497

9598

96-
async def test_failed_well_known(requestor, fail_well_known_client):
97-
with pytest.raises(ConfigException):
98-
await requestor.refresh_token('my-refresh-token')
99+
async def test_failed_well_known(requestor):
100+
with fail_well_known_client():
101+
with pytest.raises(ConfigException):
102+
await requestor.refresh_token('my-refresh-token')
99103

100104

101-
async def test_failed_refresh_token(requestor, fail_token_request_client):
102-
with pytest.raises(ConfigException):
103-
await requestor.refresh_token('my-refresh-token')
105+
async def test_failed_refresh_token(requestor):
106+
with fail_token_request_client():
107+
with pytest.raises(ConfigException):
108+
await requestor.refresh_token('my-refresh-token')

test-requirements.txt

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ nose>=1.3.7
88
pluggy>=0.3.1
99
py>=1.4.31
1010
pytest
11-
pytest-aiohttp
1211
pytest-xdist
1312
randomize>=0.13
1413
recommonmark

tox.ini

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ deps = -r{toxinidir}/test-requirements.txt
99
-r{toxinidir}/requirements.txt
1010
commands =
1111
python -V
12-
py.test -vvv -s --ignore=kubernetes/e2e_test {posargs}
12+
py.test -vvv -s --ignore=kubernetes/e2e_test
1313

1414
[testenv:docs]
1515
commands =

0 commit comments

Comments
 (0)