Allow non interactive first start

This commit is contained in:
vrde 2016-02-18 16:27:24 +01:00
parent 5ebe9e9349
commit c695f0950e
2 changed files with 32 additions and 4 deletions

View File

@ -4,6 +4,7 @@
import os
import logging
import argparse
import copy
import bigchaindb
import bigchaindb.config_utils
@ -48,13 +49,15 @@ def run_configure(args, skip_if_exists=False):
return
# Patch the default configuration with the new values
conf = bigchaindb._config
conf = copy.deepcopy(bigchaindb._config)
print('Generating keypair')
conf['keypair']['private'], conf['keypair']['public'] = generate_key_pair()
for key in ('host', 'port', 'name'):
val = conf['database'][key]
conf['database'][key] = input('Database {}? (default `{}`): '.format(key, val)) or val
if not args.yes:
for key in ('host', 'port', 'name'):
val = conf['database'][key]
conf['database'][key] = input('Database {}? (default `{}`): '.format(key, val)) or val
bigchaindb.config_utils.write_config(conf, config_path)
print('Ready to go!')

View File

@ -1,5 +1,6 @@
from argparse import Namespace
from pprint import pprint
import copy
import pytest
@ -71,6 +72,30 @@ def test_bigchain_run_start(mock_run_configure, mock_file_config,
run_start(args)
def test_bigchain_run_start_assume_yes_create_default_config(monkeypatch, mock_processes_start,
mock_generate_key_pair, mock_db_init_with_existing_db):
import bigchaindb
from bigchaindb.commands.bigchain import run_start
from bigchaindb import config_utils
value = {}
expected_config = copy.deepcopy(bigchaindb._config)
expected_config['keypair']['public'] = 'pubkey'
expected_config['keypair']['private'] = 'privkey'
def mock_write_config(newconfig, filename=None):
value['return'] = newconfig
monkeypatch.setattr(config_utils, 'write_config', mock_write_config)
monkeypatch.setattr(config_utils, 'file_config', lambda x: config_utils.dict_config(value['return']))
monkeypatch.setattr('os.path.exists', lambda path: False)
args = Namespace(config=None, yes=True)
run_start(args)
assert value['return'] == expected_config
# TODO Please beware, that if debugging, the "-s" switch for pytest will
# interfere with capsys.
# See related issue: https://github.com/pytest-dev/pytest/issues/128