Commit 1598cffa authored by Theophile GENTILHOMME's avatar Theophile GENTILHOMME
Browse files

[test][test_config] Reshape tests

More consistent with other tests framework
parent b6dad7c6
......@@ -43,12 +43,24 @@ from .. import common
from beat.cmdline.scripts import main_cli
def test_config_list():
def call(*args, **kwargs):
'''A central mechanism to call the main routine with the right parameters'''
use_prefix = kwargs.get('prefix', tmp_prefix)
runner = CliRunner()
result = runner.invoke(main_cli.main, ['config', 'show'])
nose.tools.eq_(result.exit_code, 0, result.output)
result = runner.invoke(
main_cli.main,
['--test-mode', '--prefix', use_prefix] +
list(args)
)
if result.exit_code != 0:
click.echo(result.output)
return result.exit_code
def test_config_list():
nose.tools.eq_(call('config', 'show'), 0)
def test_config_cache():
cache_dir = 'cache'
......@@ -64,94 +76,65 @@ def test_config_cache():
@nose.tools.with_setup(teardown=cleanup)
def test_set_local_token():
token_value = '123456abcdefffff'
runner = CliRunner()
with runner.isolated_filesystem():
result = runner.invoke(main_cli.main, ['config', 'set', '--local',
'token', token_value])
nose.tools.eq_(result.exit_code, 0, result.output)
config = '.beatrc'
assert os.path.exists(config)
with open(config, 'rt') as f: contents = simplejson.load(f)
assert contents['token'] == token_value
nose.tools.eq_(call('config', 'set', '--local', 'token', token_value), 0)
config = '.beatrc'
assert os.path.exists(config)
with open(config, 'rt') as f: contents = simplejson.load(f)
assert contents['token'] == token_value
@nose.tools.with_setup(teardown=cleanup)
def test_set_local_multiple():
token_value = '123456abcde123456abcde123456abcdefff123456abcdef'
runner = CliRunner()
with runner.isolated_filesystem():
result = runner.invoke(main_cli.main, ['config', 'set', '--local',
'token', token_value])
nose.tools.eq_(result.exit_code, 0, result.output)
config = '.beatrc'
assert os.path.exists(config)
with open(config, 'rt') as f: contents = simplejson.load(f)
assert contents['token'] == token_value
nose.tools.eq_(call('config', 'set', '--local', 'token', token_value), 0)
config = '.beatrc'
assert os.path.exists(config)
with open(config, 'rt') as f: contents = simplejson.load(f)
assert contents['token'] == token_value
# then we reduce the token size and see if the written file gets messed-up
token_value = '123456'
result = runner.invoke(main_cli.main, ['config', 'set', '--local',
'token', token_value])
nose.tools.eq_(result.exit_code, 0, result.output)
assert os.path.exists(config)
with open(config, 'rt') as f: contents = simplejson.load(f)
assert contents['token'] == token_value
# then we reduce the token size and see if the written file gets messed-up
token_value = '123456'
nose.tools.eq_(call('config', 'set', '--local', 'token', token_value), 0)
assert os.path.exists(config)
with open(config, 'rt') as f: contents = simplejson.load(f)
assert contents['token'] == token_value
@nose.tools.with_setup(teardown=cleanup)
def test_set_local_atnt_db():
db_config = 'database/atnt'
db_path = './atnt_db'
runner = CliRunner()
with runner.isolated_filesystem():
result = runner.invoke(main_cli.main, ['config', 'set', '--local',
db_config, db_path])
nose.tools.eq_(result.exit_code, 0, result.output)
config = '.beatrc'
assert os.path.exists(config)
with open(config, 'rt') as f: contents = simplejson.load(f)
assert contents[db_config] == db_path
nose.tools.eq_(call('config', 'set', '--local', db_config, db_path), 0)
config = '.beatrc'
assert os.path.exists(config)
with open(config, 'rt') as f: contents = simplejson.load(f)
assert contents[db_config] == db_path
@nose.tools.with_setup(teardown=cleanup)
def test_set_get_local_atnt_db():
db_config = 'database/atnt'
db_path = './atnt_db'
runner = CliRunner()
with runner.isolated_filesystem():
result = runner.invoke(main_cli.main, ['config', 'set', '--local',
db_config, db_path])
nose.tools.eq_(result.exit_code, 0, result.output)
result = runner.invoke(main_cli.main, ['config', 'get', db_config])
nose.tools.eq_(result.exit_code, 0, result.output)
assert db_path in result.output
nose.tools.eq_(call('config', 'set', '--local', db_config, db_path), 0)
nose.tools.eq_(call('config', 'get', db_config), 0)
@nose.tools.with_setup(teardown=cleanup)
def test_set_bad_config_key():
db_config = 'fail'
runner = CliRunner()
with runner.isolated_filesystem():
result = runner.invoke(main_cli.main, ['config', 'set', '--local',
db_config, db_config])
nose.tools.eq_(result.exit_code, 1, result.output)
nose.tools.eq_(call('config', 'set', '--local', db_config, db_config), 1)
@nose.tools.with_setup(teardown=cleanup)
def test_get_bad_config_key():
db_config = 'fail'
runner = CliRunner()
with runner.isolated_filesystem():
result = runner.invoke(main_cli.main, ['config', 'get', db_config])
nose.tools.eq_(result.exit_code, -1, result.output)
nose.tools.eq_(call('config', 'get', db_config), -1)
@nose.tools.with_setup(teardown=cleanup)
def test_get_token():
runner = CliRunner()
with runner.isolated_filesystem():
result = runner.invoke(main_cli.main, ['config', 'get', 'token'])
nose.tools.eq_(result.exit_code, 0, result.output)
nose.tools.eq_(call('config', 'get', 'user'), 0)
@nose.tools.with_setup(teardown=cleanup)
def test_get_editor():
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment