mirror of
https://github.com/bigchaindb/bigchaindb.git
synced 2024-10-13 13:34:05 +00:00
Allow non interactive first start
This commit is contained in:
parent
5ebe9e9349
commit
c695f0950e
@ -4,6 +4,7 @@
|
|||||||
import os
|
import os
|
||||||
import logging
|
import logging
|
||||||
import argparse
|
import argparse
|
||||||
|
import copy
|
||||||
|
|
||||||
import bigchaindb
|
import bigchaindb
|
||||||
import bigchaindb.config_utils
|
import bigchaindb.config_utils
|
||||||
@ -48,13 +49,15 @@ def run_configure(args, skip_if_exists=False):
|
|||||||
return
|
return
|
||||||
|
|
||||||
# Patch the default configuration with the new values
|
# Patch the default configuration with the new values
|
||||||
conf = bigchaindb._config
|
conf = copy.deepcopy(bigchaindb._config)
|
||||||
|
|
||||||
print('Generating keypair')
|
print('Generating keypair')
|
||||||
conf['keypair']['private'], conf['keypair']['public'] = generate_key_pair()
|
conf['keypair']['private'], conf['keypair']['public'] = generate_key_pair()
|
||||||
|
|
||||||
for key in ('host', 'port', 'name'):
|
if not args.yes:
|
||||||
val = conf['database'][key]
|
for key in ('host', 'port', 'name'):
|
||||||
conf['database'][key] = input('Database {}? (default `{}`): '.format(key, val)) or val
|
val = conf['database'][key]
|
||||||
|
conf['database'][key] = input('Database {}? (default `{}`): '.format(key, val)) or val
|
||||||
|
|
||||||
bigchaindb.config_utils.write_config(conf, config_path)
|
bigchaindb.config_utils.write_config(conf, config_path)
|
||||||
print('Ready to go!')
|
print('Ready to go!')
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
from argparse import Namespace
|
from argparse import Namespace
|
||||||
from pprint import pprint
|
from pprint import pprint
|
||||||
|
import copy
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
@ -71,6 +72,30 @@ def test_bigchain_run_start(mock_run_configure, mock_file_config,
|
|||||||
run_start(args)
|
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
|
# TODO Please beware, that if debugging, the "-s" switch for pytest will
|
||||||
# interfere with capsys.
|
# interfere with capsys.
|
||||||
# See related issue: https://github.com/pytest-dev/pytest/issues/128
|
# See related issue: https://github.com/pytest-dev/pytest/issues/128
|
||||||
|
Loading…
x
Reference in New Issue
Block a user