Skip to content
Snippets Groups Projects
Verified Commit 7f928a07 authored by Antoine R. Dumont's avatar Antoine R. Dumont
Browse files

api.tests.test_async: Simplify fixture setup

parent 1657fb82
No related branches found
No related tags found
1 merge request!173api.tests.test_async: Simplify fixture setup
......@@ -96,10 +96,12 @@ def async_app():
return app
async def test_get_simple(async_app, aiohttp_client) -> None:
assert async_app is not None
@pytest.fixture
def cli(async_app, aiohttp_client, loop):
return loop.run_until_complete(aiohttp_client(async_app))
cli = await aiohttp_client(async_app)
async def test_get_simple(cli) -> None:
resp = await cli.get("/")
assert resp.status == 200
check_mimetype(resp.headers["Content-Type"], "application/x-msgpack")
......@@ -108,8 +110,7 @@ async def test_get_simple(async_app, aiohttp_client) -> None:
assert value == "toor"
async def test_get_server_exception(async_app, aiohttp_client) -> None:
cli = await aiohttp_client(async_app)
async def test_get_server_exception(cli) -> None:
resp = await cli.get("/server_exception")
assert resp.status == 500
data = await resp.read()
......@@ -117,8 +118,7 @@ async def test_get_server_exception(async_app, aiohttp_client) -> None:
assert data["exception"]["type"] == "TestServerException"
async def test_get_client_error(async_app, aiohttp_client) -> None:
cli = await aiohttp_client(async_app)
async def test_get_client_error(cli) -> None:
resp = await cli.get("/client_error")
assert resp.status == 400
data = await resp.read()
......@@ -126,8 +126,7 @@ async def test_get_client_error(async_app, aiohttp_client) -> None:
assert data["exception"]["type"] == "TestClientError"
async def test_get_simple_nego(async_app, aiohttp_client) -> None:
cli = await aiohttp_client(async_app)
async def test_get_simple_nego(cli) -> None:
for ctype in ("x-msgpack", "json"):
resp = await cli.get("/", headers={"Accept": "application/%s" % ctype})
assert resp.status == 200
......@@ -135,18 +134,16 @@ async def test_get_simple_nego(async_app, aiohttp_client) -> None:
assert (await decode_request(resp)) == "toor"
async def test_get_struct(async_app, aiohttp_client) -> None:
async def test_get_struct(cli) -> None:
"""Test returned structured from a simple GET data is OK"""
cli = await aiohttp_client(async_app)
resp = await cli.get("/struct")
assert resp.status == 200
check_mimetype(resp.headers["Content-Type"], "application/x-msgpack")
assert (await decode_request(resp)) == STRUCT
async def test_get_struct_nego(async_app, aiohttp_client) -> None:
async def test_get_struct_nego(cli) -> None:
"""Test returned structured from a simple GET data is OK"""
cli = await aiohttp_client(async_app)
for ctype in ("x-msgpack", "json"):
resp = await cli.get("/struct", headers={"Accept": "application/%s" % ctype})
assert resp.status == 200
......@@ -154,9 +151,8 @@ async def test_get_struct_nego(async_app, aiohttp_client) -> None:
assert (await decode_request(resp)) == STRUCT
async def test_post_struct_msgpack(async_app, aiohttp_client) -> None:
async def test_post_struct_msgpack(cli) -> None:
"""Test that msgpack encoded posted struct data is returned as is"""
cli = await aiohttp_client(async_app)
# simple struct
resp = await cli.post(
"/echo",
......@@ -177,10 +173,8 @@ async def test_post_struct_msgpack(async_app, aiohttp_client) -> None:
assert (await decode_request(resp)) == STRUCT
async def test_post_struct_json(async_app, aiohttp_client) -> None:
async def test_post_struct_json(cli) -> None:
"""Test that json encoded posted struct data is returned as is"""
cli = await aiohttp_client(async_app)
resp = await cli.post(
"/echo",
headers={"Content-Type": "application/json"},
......@@ -201,13 +195,11 @@ async def test_post_struct_json(async_app, aiohttp_client) -> None:
assert (await decode_request(resp)) == STRUCT
async def test_post_struct_nego(async_app, aiohttp_client) -> None:
async def test_post_struct_nego(cli) -> None:
"""Test that json encoded posted struct data is returned as is
using content negotiation (accept json or msgpack).
"""
cli = await aiohttp_client(async_app)
for ctype in ("x-msgpack", "json"):
resp = await cli.post(
"/echo",
......@@ -222,13 +214,11 @@ async def test_post_struct_nego(async_app, aiohttp_client) -> None:
assert (await decode_request(resp)) == STRUCT
async def test_post_struct_no_nego(async_app, aiohttp_client) -> None:
async def test_post_struct_no_nego(cli) -> None:
"""Test that json encoded posted struct data is returned as msgpack
when using non-negotiation-compatible handlers.
"""
cli = await aiohttp_client(async_app)
for ctype in ("x-msgpack", "json"):
resp = await cli.post(
"/echo-no-nego",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment