Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions tests/conftest.py

This file was deleted.

53 changes: 25 additions & 28 deletions tests/test_openapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,10 @@ async def ping_partial(request):
return web.Response(text="pong")


async def test_swagger_ui(aiohttp_client, loop):
async def test_swagger_ui(aiohttp_client, event_loop):
TESTS_PATH = abspath(join(dirname(__file__)))

app = web.Application(loop=loop)
app = web.Application(loop=event_loop)
setup_swagger(app,
swagger_from_file=TESTS_PATH + "/data/example_swagger.yaml",
ui_version=3
Expand All @@ -113,10 +113,10 @@ async def test_swagger_ui(aiohttp_client, loop):
assert retrieved == loaded


async def test_swagger_file_url(aiohttp_client, loop):
async def test_swagger_file_url(aiohttp_client, event_loop):
TESTS_PATH = abspath(join(dirname(__file__)))

app = web.Application(loop=loop)
app = web.Application(loop=event_loop)
setup_swagger(app,
ui_version=3,
swagger_from_file=TESTS_PATH + "/data/example_swagger.yaml")
Expand All @@ -129,9 +129,8 @@ async def test_swagger_file_url(aiohttp_client, loop):
assert '/example2' in result['paths']
assert 'API Title' in result['info']['title']


async def test_partial_swagger_file(aiohttp_client, loop):
app = web.Application(loop=loop)
async def test_partial_swagger_file(aiohttp_client, event_loop):
app = web.Application(loop=event_loop)
app.router.add_route('GET', "/ping-partial", ping_partial)
setup_swagger(app, ui_version=3)

Expand All @@ -141,9 +140,8 @@ async def test_partial_swagger_file(aiohttp_client, loop):
result = await resp1.json()
assert '/ping-partial' in result['paths']


async def test_custom_swagger(aiohttp_client, loop):
app = web.Application(loop=loop)
async def test_custom_swagger(aiohttp_client, event_loop):
app = web.Application(loop=event_loop)
app.router.add_route('GET', "/ping", ping)
description = "Test Custom Swagger"
setup_swagger(app,
Expand All @@ -161,9 +159,8 @@ async def test_custom_swagger(aiohttp_client, loop):
assert '/ping' in result['paths']
assert 'Test Custom Title' in result['info']['title']


async def test_swagger_home_decorator(aiohttp_client, loop):
app = web.Application(loop=loop)
async def test_swagger_home_decorator(aiohttp_client, event_loop):
app = web.Application(loop=event_loop)
app.router.add_route('GET', "/ping", ping)
description = "Test Custom Swagger"
setup_swagger(app,
Expand All @@ -183,8 +180,8 @@ async def test_swagger_home_decorator(aiohttp_client, loop):
assert 'Test Custom Title' in result['info']['title']


async def test_swagger_def_decorator(aiohttp_client, loop):
app = web.Application(loop=loop)
async def test_swagger_def_decorator(aiohttp_client, event_loop):
app = web.Application(loop=event_loop)
app.router.add_route('GET', "/ping", ping)
description = "Test Custom Swagger"
setup_swagger(app,
Expand All @@ -210,8 +207,8 @@ def swagger_info():
return yaml.full_load(open(filename).read())


async def test_swagger_info(aiohttp_client, loop, swagger_info):
app = web.Application(loop=loop)
async def test_swagger_info(aiohttp_client, event_loop, swagger_info):
app = web.Application(loop=event_loop)
app.router.add_route('GET', "/ping", ping)
description = "Test Custom Swagger"
setup_swagger(app,
Expand All @@ -228,8 +225,8 @@ async def test_swagger_info(aiohttp_client, loop, swagger_info):
assert 'API Title' in result['info']['title']


async def test_undocumented_fn(aiohttp_client, loop):
app = web.Application(loop=loop)
async def test_undocumented_fn(aiohttp_client, event_loop):
app = web.Application(loop=event_loop)
app.router.add_route('GET', "/undoc_ping", undoc_ping)
setup_swagger(app, ui_version=3)
client = await aiohttp_client(app)
Expand All @@ -241,8 +238,8 @@ async def test_undocumented_fn(aiohttp_client, loop):
assert not result['paths']


async def test_wrong_method(aiohttp_client, loop):
app = web.Application(loop=loop)
async def test_wrong_method(aiohttp_client, event_loop):
app = web.Application(loop=event_loop)
app.router.add_route('POST', "/post_ping", ping)
setup_swagger(app, ui_version=3)
client = await aiohttp_client(app)
Expand All @@ -256,8 +253,8 @@ async def test_wrong_method(aiohttp_client, loop):
assert resp.status == 405


async def test_class_view(aiohttp_client, loop):
app = web.Application(loop=loop)
async def test_class_view(aiohttp_client, event_loop):
app = web.Application(loop=event_loop)
app.router.add_route('*', "/class_view", ClassView)
setup_swagger(app, ui_version=3)

Expand Down Expand Up @@ -294,10 +291,10 @@ async def test_class_view(aiohttp_client, loop):
assert "patch" not in result['paths']["/class_view"]


async def test_data_defs(aiohttp_client, loop):
async def test_data_defs(aiohttp_client, event_loop):
TESTS_PATH = abspath(join(dirname(__file__)))
file = open(TESTS_PATH + "/data/example_data_definitions.json")
app = web.Application(loop=loop)
app = web.Application(loop=event_loop)
app.router.add_route('GET', "/users", users_with_data_def)
setup_swagger(app, ui_version=3, definitions=json.loads(file.read()))
file.close()
Expand All @@ -311,11 +308,11 @@ async def test_data_defs(aiohttp_client, loop):
assert result['components']['schemas']['User']['properties']['permissions']['items']['$ref'] is not None


async def test_sub_app(aiohttp_client, loop):
sub_app = web.Application(loop=loop)
async def test_sub_app(aiohttp_client, event_loop):
sub_app = web.Application(loop=event_loop)
sub_app.router.add_route('*', "/class_view", ClassView)
setup_swagger(sub_app, ui_version=3, api_base_url='/sub_app')
app = web.Application(loop=loop)
app = web.Application(loop=event_loop)
app.add_subapp(prefix='/sub_app', subapp=sub_app)

client = await aiohttp_client(app)
Expand Down
62 changes: 31 additions & 31 deletions tests/test_swagger.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ async def ping_partial(request):
return web.Response(text="pong")


async def test_ping(aiohttp_client, loop):
app = web.Application(loop=loop)
async def test_ping(aiohttp_client, event_loop):
app = web.Application(loop=event_loop)
app.router.add_route('GET', "/ping", ping)
client = await aiohttp_client(app)
resp = await client.get('/ping')
Expand All @@ -103,11 +103,11 @@ async def test_ping(aiohttp_client, loop):
assert 'pong' in text


async def test_swagger_ui(aiohttp_client, loop):
async def test_swagger_ui(aiohttp_client, event_loop):

TESTS_PATH = abspath(join(dirname(__file__)))

app = web.Application(loop=loop)
app = web.Application(loop=event_loop)
setup_swagger(app,
swagger_from_file=TESTS_PATH + "/data/example_swagger.yaml")

Expand All @@ -122,10 +122,10 @@ async def test_swagger_ui(aiohttp_client, loop):
assert retrieved == loaded


async def test_swagger_ui3(aiohttp_client, loop):
async def test_swagger_ui3(aiohttp_client, event_loop):
TESTS_PATH = abspath(join(dirname(__file__)))

app = web.Application(loop=loop)
app = web.Application(loop=event_loop)
setup_swagger(app,
swagger_from_file=TESTS_PATH + "/data/example_swagger.yaml",
ui_version=3
Expand All @@ -142,10 +142,10 @@ async def test_swagger_ui3(aiohttp_client, loop):
assert retrieved == loaded


async def test_swagger_file_url(aiohttp_client, loop):
async def test_swagger_file_url(aiohttp_client, event_loop):
TESTS_PATH = abspath(join(dirname(__file__)))

app = web.Application(loop=loop)
app = web.Application(loop=event_loop)
setup_swagger(app,
swagger_from_file=TESTS_PATH + "/data/example_swagger.yaml")

Expand All @@ -158,8 +158,8 @@ async def test_swagger_file_url(aiohttp_client, loop):
assert 'API Title' in result['info']['title']


async def test_partial_swagger_file(aiohttp_client, loop):
app = web.Application(loop=loop)
async def test_partial_swagger_file(aiohttp_client, event_loop):
app = web.Application(loop=event_loop)
app.router.add_route('GET', "/ping-partial", ping_partial)
setup_swagger(app)

Expand All @@ -170,8 +170,8 @@ async def test_partial_swagger_file(aiohttp_client, loop):
assert '/ping-partial' in result['paths']


async def test_custom_swagger(aiohttp_client, loop):
app = web.Application(loop=loop)
async def test_custom_swagger(aiohttp_client, event_loop):
app = web.Application(loop=event_loop)
app.router.add_route('GET', "/ping", ping)
description = "Test Custom Swagger"
setup_swagger(app,
Expand All @@ -189,8 +189,8 @@ async def test_custom_swagger(aiohttp_client, loop):
assert 'Test Custom Title' in result['info']['title']


async def test_swagger_home_decorator(aiohttp_client, loop):
app = web.Application(loop=loop)
async def test_swagger_home_decorator(aiohttp_client, event_loop):
app = web.Application(loop=event_loop)
app.router.add_route('GET', "/ping", ping)
description = "Test Custom Swagger"
setup_swagger(app,
Expand All @@ -209,8 +209,8 @@ async def test_swagger_home_decorator(aiohttp_client, loop):
assert 'Test Custom Title' in result['info']['title']


async def test_swagger_def_decorator(aiohttp_client, loop):
app = web.Application(loop=loop)
async def test_swagger_def_decorator(aiohttp_client, event_loop):
app = web.Application(loop=event_loop)
app.router.add_route('GET', "/ping", ping)
description = "Test Custom Swagger"
setup_swagger(app,
Expand All @@ -235,8 +235,8 @@ def swagger_info():
return yaml.full_load(open(filename).read())


async def test_swagger_info(aiohttp_client, loop, swagger_info):
app = web.Application(loop=loop)
async def test_swagger_info(aiohttp_client, event_loop, swagger_info):
app = web.Application(loop=event_loop)
app.router.add_route('GET', "/ping", ping)
description = "Test Custom Swagger"
setup_swagger(app,
Expand All @@ -252,8 +252,8 @@ async def test_swagger_info(aiohttp_client, loop, swagger_info):
assert 'API Title' in result['info']['title']


async def test_undocumented_fn(aiohttp_client, loop):
app = web.Application(loop=loop)
async def test_undocumented_fn(aiohttp_client, event_loop):
app = web.Application(loop=event_loop)
app.router.add_route('GET', "/undoc_ping", undoc_ping)
setup_swagger(app)
client = await aiohttp_client(app)
Expand All @@ -265,8 +265,8 @@ async def test_undocumented_fn(aiohttp_client, loop):
assert not result['paths']


async def test_wrong_method(aiohttp_client, loop):
app = web.Application(loop=loop)
async def test_wrong_method(aiohttp_client, event_loop):
app = web.Application(loop=event_loop)
app.router.add_route('POST', "/post_ping", ping)
setup_swagger(app)
client = await aiohttp_client(app)
Expand All @@ -279,8 +279,8 @@ async def test_wrong_method(aiohttp_client, loop):
resp = await client.get('/post_ping')
assert resp.status == 405

async def test_class_view_single_method(aiohttp_client, loop):
app = web.Application(loop=loop)
async def test_class_view_single_method(aiohttp_client, event_loop):
app = web.Application(loop=event_loop)
app.router.add_route('GET', "/class_view", ClassView)
setup_swagger(app)

Expand All @@ -303,8 +303,8 @@ async def test_class_view_single_method(aiohttp_client, loop):
assert "post" not in result['paths']["/class_view"]


async def test_class_view_multiple_methods(aiohttp_client, loop):
app = web.Application(loop=loop)
async def test_class_view_multiple_methods(aiohttp_client, event_loop):
app = web.Application(loop=event_loop)
app.router.add_route('*', "/class_view", ClassView)
setup_swagger(app)

Expand Down Expand Up @@ -341,10 +341,10 @@ async def test_class_view_multiple_methods(aiohttp_client, loop):
assert "patch" not in result['paths']["/class_view"]


async def test_data_defs(aiohttp_client, loop):
async def test_data_defs(aiohttp_client, event_loop):
TESTS_PATH = abspath(join(dirname(__file__)))
file = open(TESTS_PATH + "/data/example_data_definitions.json")
app = web.Application(loop=loop)
app = web.Application(loop=event_loop)
app.router.add_route('GET', "/users", users_with_data_def)
setup_swagger(app, definitions=json.loads(file.read()))
file.close()
Expand All @@ -358,11 +358,11 @@ async def test_data_defs(aiohttp_client, loop):
assert result['definitions']['User']['properties']['permissions']['items']['$ref'] is not None


async def test_sub_app(aiohttp_client, loop):
sub_app = web.Application(loop=loop)
async def test_sub_app(aiohttp_client, event_loop):
sub_app = web.Application(loop=event_loop)
sub_app.router.add_route('*', "/class_view", ClassView)
setup_swagger(sub_app, api_base_url='/sub_app')
app = web.Application(loop=loop)
app = web.Application(loop=event_loop)
app.add_subapp(prefix='/sub_app', subapp=sub_app)

client = await aiohttp_client(app)
Expand Down
5 changes: 4 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,7 @@ envlist = py35, py36, py37, py38

[testenv]
deps = -rrequirements-dev.txt
commands = py.test
commands = py.test

[pytest]
asyncio-default-fixture-loop-scope=function