-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Also added end-to-end testing with tox
- Loading branch information
Showing
9 changed files
with
96 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import pathlib | ||
import subprocess | ||
|
||
import aiohttp | ||
import pytest | ||
|
||
|
||
@pytest.yield_fixture | ||
def create_app(event_loop, unused_tcp_port): | ||
app = handler = srv = client_session = None | ||
|
||
async def create(): | ||
nonlocal app, handler, srv, client_session | ||
import aiohttpdemo_polls.main | ||
app, host, port = await aiohttpdemo_polls.main.init(event_loop) | ||
handler = app.make_handler(debug=True, keep_alive_on=False) | ||
srv = await event_loop.create_server(handler, '127.0.0.1', port) | ||
url = "http://127.0.0.1:{}".format(port) | ||
client_session = aiohttp.ClientSession() | ||
return app, url, client_session | ||
|
||
yield create | ||
|
||
async def finish(): | ||
await handler.finish_connections() | ||
await app.finish() | ||
await client_session.close() | ||
srv.close() | ||
await srv.wait_closed() | ||
|
||
event_loop.run_until_complete(finish()) | ||
|
||
|
||
BASE_DIR = pathlib.Path(__file__).parent.parent | ||
|
||
|
||
@pytest.fixture | ||
def app_db(): | ||
subprocess.call( | ||
[(BASE_DIR / 'sql' / 'install.sh').as_posix()], | ||
shell=True, | ||
cwd=BASE_DIR.as_posix() | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
""" | ||
Integration tests. They need a running database. | ||
Beware, they destroy your db using sudo. | ||
""" | ||
|
||
async def _test_index(create_app): | ||
app, url, client_session = await create_app() | ||
async with client_session.get('{}/'.format(url)) as response: | ||
assert response.status == 200, await response.text() | ||
|
||
|
||
def test_index(create_app, event_loop, app_db): | ||
event_loop.run_until_complete(_test_index(create_app)) | ||
|
||
|
||
async def _test_results(create_app): | ||
app, url, client_session = await create_app() | ||
async with client_session.get('{}/results'.format(url)) as response: | ||
assert response.status == 200, await response.text() | ||
|
||
|
||
def test_results(create_app, event_loop, app_db): | ||
event_loop.run_until_complete(_test_results(create_app)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
[tox] | ||
envlist = py35 | ||
|
||
[testenv] | ||
deps = | ||
pytest | ||
pytest-asyncio==0.3.0 | ||
usedevelop = True | ||
commands=py.test tests -s |