2018-12-30 11:18:06 +00:00
|
|
|
import logging
|
|
|
|
import asyncio
|
|
|
|
|
|
|
|
from sanic.config import BASE_LOGO
|
|
|
|
|
2018-12-30 12:07:21 +00:00
|
|
|
try:
|
|
|
|
import uvloop # noqa
|
2018-12-31 11:40:07 +00:00
|
|
|
|
2018-12-30 12:07:21 +00:00
|
|
|
ROW = 0
|
|
|
|
except BaseException:
|
|
|
|
ROW = 1
|
|
|
|
|
2018-12-30 11:18:06 +00:00
|
|
|
|
2018-12-30 11:46:08 +00:00
|
|
|
def test_logo_base(app, caplog):
|
2019-01-15 13:17:57 +00:00
|
|
|
server = app.create_server(
|
|
|
|
debug=True, return_asyncio_server=True)
|
2018-12-30 11:46:08 +00:00
|
|
|
loop = asyncio.new_event_loop()
|
|
|
|
asyncio.set_event_loop(loop)
|
|
|
|
loop._stopping = False
|
2018-12-30 11:18:06 +00:00
|
|
|
|
|
|
|
with caplog.at_level(logging.DEBUG):
|
2018-12-30 11:46:08 +00:00
|
|
|
_server = loop.run_until_complete(server)
|
|
|
|
|
|
|
|
_server.close()
|
|
|
|
loop.run_until_complete(_server.wait_closed())
|
|
|
|
app.stop()
|
2018-12-30 11:18:06 +00:00
|
|
|
|
2018-12-30 12:07:21 +00:00
|
|
|
assert caplog.record_tuples[ROW][1] == logging.DEBUG
|
|
|
|
assert caplog.record_tuples[ROW][2] == BASE_LOGO
|
2018-12-30 11:18:06 +00:00
|
|
|
|
|
|
|
|
2018-12-30 11:46:08 +00:00
|
|
|
def test_logo_false(app, caplog):
|
2018-12-30 11:18:06 +00:00
|
|
|
app.config.LOGO = False
|
2018-12-30 11:46:08 +00:00
|
|
|
|
2019-01-15 13:17:57 +00:00
|
|
|
server = app.create_server(
|
|
|
|
debug=True, return_asyncio_server=True)
|
2018-12-30 11:46:08 +00:00
|
|
|
loop = asyncio.new_event_loop()
|
|
|
|
asyncio.set_event_loop(loop)
|
|
|
|
loop._stopping = False
|
|
|
|
|
2018-12-30 11:18:06 +00:00
|
|
|
with caplog.at_level(logging.DEBUG):
|
2018-12-30 11:46:08 +00:00
|
|
|
_server = loop.run_until_complete(server)
|
|
|
|
|
|
|
|
_server.close()
|
|
|
|
loop.run_until_complete(_server.wait_closed())
|
|
|
|
app.stop()
|
2018-12-30 11:18:06 +00:00
|
|
|
|
2018-12-30 12:07:21 +00:00
|
|
|
assert caplog.record_tuples[ROW][1] == logging.INFO
|
|
|
|
assert caplog.record_tuples[ROW][2] == "Goin' Fast @ http://127.0.0.1:8000"
|
2018-12-30 11:18:06 +00:00
|
|
|
|
|
|
|
|
2018-12-30 11:46:08 +00:00
|
|
|
def test_logo_true(app, caplog):
|
2018-12-30 11:18:06 +00:00
|
|
|
app.config.LOGO = True
|
2018-12-30 11:46:08 +00:00
|
|
|
|
2019-01-15 13:17:57 +00:00
|
|
|
server = app.create_server(
|
|
|
|
debug=True, return_asyncio_server=True)
|
2018-12-30 11:46:08 +00:00
|
|
|
loop = asyncio.new_event_loop()
|
|
|
|
asyncio.set_event_loop(loop)
|
|
|
|
loop._stopping = False
|
|
|
|
|
2018-12-30 11:18:06 +00:00
|
|
|
with caplog.at_level(logging.DEBUG):
|
2018-12-30 11:46:08 +00:00
|
|
|
_server = loop.run_until_complete(server)
|
|
|
|
|
|
|
|
_server.close()
|
|
|
|
loop.run_until_complete(_server.wait_closed())
|
|
|
|
app.stop()
|
2018-12-30 11:18:06 +00:00
|
|
|
|
2018-12-30 12:07:21 +00:00
|
|
|
assert caplog.record_tuples[ROW][1] == logging.DEBUG
|
|
|
|
assert caplog.record_tuples[ROW][2] == BASE_LOGO
|
2018-12-30 11:18:06 +00:00
|
|
|
|
|
|
|
|
2018-12-30 11:46:08 +00:00
|
|
|
def test_logo_custom(app, caplog):
|
2018-12-30 11:18:06 +00:00
|
|
|
app.config.LOGO = "My Custom Logo"
|
2018-12-30 11:46:08 +00:00
|
|
|
|
2019-01-15 13:17:57 +00:00
|
|
|
server = app.create_server(
|
|
|
|
debug=True, return_asyncio_server=True)
|
2018-12-30 11:46:08 +00:00
|
|
|
loop = asyncio.new_event_loop()
|
|
|
|
asyncio.set_event_loop(loop)
|
|
|
|
loop._stopping = False
|
|
|
|
|
2018-12-30 11:18:06 +00:00
|
|
|
with caplog.at_level(logging.DEBUG):
|
2018-12-30 11:46:08 +00:00
|
|
|
_server = loop.run_until_complete(server)
|
|
|
|
|
|
|
|
_server.close()
|
|
|
|
loop.run_until_complete(_server.wait_closed())
|
|
|
|
app.stop()
|
2018-12-30 11:18:06 +00:00
|
|
|
|
2018-12-30 12:07:21 +00:00
|
|
|
assert caplog.record_tuples[ROW][1] == logging.DEBUG
|
|
|
|
assert caplog.record_tuples[ROW][2] == "My Custom Logo"
|