mirror of
https://github.com/bigchaindb/bigchaindb.git
synced 2024-10-13 13:34:05 +00:00
Add tests for setting log-level from CLI
This commit is contained in:
parent
d688e695e6
commit
f549b00813
@ -220,11 +220,14 @@ def write_config(config, filename=None):
|
|||||||
json.dump(config, f, indent=4)
|
json.dump(config, f, indent=4)
|
||||||
|
|
||||||
|
|
||||||
|
def is_configured():
|
||||||
|
return bool(bigchaindb.config.get('CONFIGURED'))
|
||||||
|
|
||||||
|
|
||||||
def autoconfigure(filename=None, config=None, force=False):
|
def autoconfigure(filename=None, config=None, force=False):
|
||||||
"""Run ``file_config`` and ``env_config`` if the module has not
|
"""Run ``file_config`` and ``env_config`` if the module has not
|
||||||
been initialized."""
|
been initialized."""
|
||||||
|
if not force and is_configured():
|
||||||
if not force and bigchaindb.config.get('CONFIGURED'):
|
|
||||||
logger.debug('System already configured, skipping autoconfiguration')
|
logger.debug('System already configured, skipping autoconfiguration')
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -1,9 +1,50 @@
|
|||||||
import argparse
|
import argparse
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
from argparse import ArgumentTypeError, Namespace
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def reset_bigchaindb_config(monkeypatch):
|
||||||
|
import bigchaindb
|
||||||
|
monkeypatch.setattr('bigchaindb.config', bigchaindb._config)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.usefixtures('ignore_local_config_file', 'reset_bigchaindb_config')
|
||||||
|
def test_configure_bigchaindb_configures_bigchaindb():
|
||||||
|
from bigchaindb.commands.utils import configure_bigchaindb
|
||||||
|
from bigchaindb.config_utils import is_configured
|
||||||
|
assert not is_configured()
|
||||||
|
|
||||||
|
@configure_bigchaindb
|
||||||
|
def test_configure(args):
|
||||||
|
assert is_configured()
|
||||||
|
|
||||||
|
args = Namespace(config=None)
|
||||||
|
test_configure(args)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.usefixtures('ignore_local_config_file',
|
||||||
|
'reset_bigchaindb_config',
|
||||||
|
'reset_logging_config')
|
||||||
|
@pytest.mark.parametrize('log_level', ('DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'))
|
||||||
|
def test_configure_bigchaindb_configures_logging(log_level):
|
||||||
|
import logging
|
||||||
|
from logging import getLogger
|
||||||
|
from bigchaindb.commands.utils import configure_bigchaindb
|
||||||
|
root_logger = getLogger()
|
||||||
|
assert root_logger.level == 0
|
||||||
|
|
||||||
|
@configure_bigchaindb
|
||||||
|
def test_configure_logger(args):
|
||||||
|
root_logger = getLogger()
|
||||||
|
assert root_logger.level == getattr(logging, log_level)
|
||||||
|
|
||||||
|
args = Namespace(config=None, log_level=log_level)
|
||||||
|
test_configure_logger(args)
|
||||||
|
|
||||||
|
|
||||||
def test_start_raises_if_command_not_implemented():
|
def test_start_raises_if_command_not_implemented():
|
||||||
from bigchaindb.commands import utils
|
from bigchaindb.commands import utils
|
||||||
from bigchaindb.commands.bigchain import create_parser
|
from bigchaindb.commands.bigchain import create_parser
|
||||||
@ -51,13 +92,13 @@ def test_mongodb_host_type():
|
|||||||
from bigchaindb.commands.utils import mongodb_host
|
from bigchaindb.commands.utils import mongodb_host
|
||||||
|
|
||||||
# bad port provided
|
# bad port provided
|
||||||
with pytest.raises(argparse.ArgumentTypeError):
|
with pytest.raises(ArgumentTypeError):
|
||||||
mongodb_host('localhost:11111111111')
|
mongodb_host('localhost:11111111111')
|
||||||
|
|
||||||
# no port information provided
|
# no port information provided
|
||||||
with pytest.raises(argparse.ArgumentTypeError):
|
with pytest.raises(ArgumentTypeError):
|
||||||
mongodb_host('localhost')
|
mongodb_host('localhost')
|
||||||
|
|
||||||
# bad host provided
|
# bad host provided
|
||||||
with pytest.raises(argparse.ArgumentTypeError):
|
with pytest.raises(ArgumentTypeError):
|
||||||
mongodb_host(':27017')
|
mongodb_host(':27017')
|
||||||
|
@ -12,6 +12,8 @@ import random
|
|||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
from logging import getLogger
|
||||||
|
from logging.config import dictConfig
|
||||||
from bigchaindb.common import crypto
|
from bigchaindb.common import crypto
|
||||||
|
|
||||||
TEST_DB_NAME = 'bigchain_test'
|
TEST_DB_NAME = 'bigchain_test'
|
||||||
@ -203,6 +205,15 @@ def ignore_local_config_file(monkeypatch):
|
|||||||
mock_file_config)
|
mock_file_config)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def reset_logging_config():
|
||||||
|
# root_logger_level = getLogger().level
|
||||||
|
root_logger_level = 'DEBUG'
|
||||||
|
dictConfig({'version': 1, 'root': {'level': 'NOTSET'}})
|
||||||
|
yield
|
||||||
|
getLogger().setLevel(root_logger_level)
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def user_sk():
|
def user_sk():
|
||||||
return USER_PRIVATE_KEY
|
return USER_PRIVATE_KEY
|
||||||
|
Loading…
x
Reference in New Issue
Block a user