-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #734 from KeepSafe/run_app
Implement web.run_app utility function
- Loading branch information
Showing
5 changed files
with
138 additions
and
20 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
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,46 @@ | ||
import asyncio | ||
import ssl | ||
|
||
from unittest import mock | ||
from aiohttp import web | ||
|
||
|
||
def test_run_app_http(loop): | ||
loop = mock.Mock(spec=asyncio.AbstractEventLoop, wrap=loop) | ||
loop.call_later(0.01, loop.stop) | ||
|
||
app = web.Application(loop=loop) | ||
|
||
web.run_app(app) | ||
|
||
loop.close.assert_called_with() | ||
loop.create_server.assert_called_with(mock.ANY, '0.0.0.0', 8080, ssl=None) | ||
|
||
|
||
def test_run_app_https(loop): | ||
loop = mock.Mock(spec=asyncio.AbstractEventLoop, wrap=loop) | ||
loop.call_later(0.01, loop.stop) | ||
|
||
app = web.Application(loop=loop) | ||
|
||
ssl_context = ssl.create_default_context() | ||
|
||
web.run_app(app, ssl_context=ssl_context) | ||
|
||
loop.close.assert_called_with() | ||
loop.create_server.assert_called_with(mock.ANY, '0.0.0.0', 8443, | ||
ssl=ssl_context) | ||
|
||
|
||
def test_run_app_nondefault_host_port(loop, unused_port): | ||
port = unused_port() | ||
host = 'localhost' | ||
|
||
loop = mock.Mock(spec=asyncio.AbstractEventLoop, wrap=loop) | ||
loop.call_later(0.01, loop.stop) | ||
|
||
app = web.Application(loop=loop) | ||
|
||
web.run_app(app, host=host, port=port) | ||
|
||
loop.create_server.assert_called_with(mock.ANY, host, port, ssl=None) |