add control of access_log argument type

This commit is contained in:
Sergey Fedoruk 2018-12-31 09:49:53 +01:00 committed by Sergey Fedoruk
parent 0b728ade3a
commit a86a10b128
2 changed files with 24 additions and 3 deletions

View File

@ -1029,7 +1029,12 @@ class Sanic:
)
# if access_log is passed explicitly change config.ACCESS_LOG
if access_log is not None:
self.config.ACCESS_LOG = access_log
if isinstance(access_log, bool):
self.config.ACCESS_LOG = access_log
else:
raise ServerError(
("'access_log' passed in 'run' should be boolean")
)
server_settings = self._helper(
host=host,
@ -1118,7 +1123,15 @@ class Sanic:
)
# if access_log is passed explicitly change config.ACCESS_LOG
if access_log is not None:
self.config.ACCESS_LOG = access_log
if isinstance(access_log, bool):
self.config.ACCESS_LOG = access_log
else:
raise ServerError(
(
"'access_log' passed in 'create_server' "
"should be boolean"
)
)
server_settings = self._helper(
host=host,

View File

@ -7,7 +7,7 @@ import pytest
from sanic import Sanic
from sanic.config import Config, DEFAULT_CONFIG
from sanic.exceptions import PyFileError
from sanic.exceptions import PyFileError, ServerError
@contextmanager
@ -223,6 +223,10 @@ def test_config_access_log_passing_in_run(app):
app.run(port=1340, access_log=True)
assert app.config.ACCESS_LOG == True
with pytest.raises(ServerError) as e:
app.run(port=1340, access_log='string')
assert str(e.value) == ("'access_log' passed in 'run' should be boolean")
async def test_config_access_log_passing_in_create_server(app):
assert app.config.ACCESS_LOG == True
@ -237,6 +241,10 @@ async def test_config_access_log_passing_in_create_server(app):
await app.create_server(port=1342, access_log=True)
assert app.config.ACCESS_LOG == True
with pytest.raises(ServerError) as e:
await app.create_server(port=1343, access_log='somestring')
assert str(e.value) == ("'access_log' passed in 'create_server' should be boolean")
def test_config_rewrite_keep_alive():
config = Config()