mirror of
https://github.com/bigchaindb/bigchaindb.git
synced 2024-10-13 13:34:05 +00:00
Merge branch 'develop' into statsd
This commit is contained in:
commit
649cc6fd69
@ -17,6 +17,6 @@ install:
|
||||
|
||||
before_script: rethinkdb --daemon
|
||||
|
||||
script: py.test -v --cov=bigchaindb
|
||||
script: py.test -n8 -v --cov=bigchaindb
|
||||
|
||||
after_success: codecov
|
||||
|
@ -4,6 +4,7 @@
|
||||
import os
|
||||
import logging
|
||||
import argparse
|
||||
import copy
|
||||
|
||||
import bigchaindb
|
||||
import bigchaindb.config_utils
|
||||
@ -11,7 +12,7 @@ from bigchaindb import db
|
||||
from bigchaindb.exceptions import DatabaseAlreadyExists
|
||||
from bigchaindb.commands.utils import base_parser, start
|
||||
from bigchaindb.processes import Processes
|
||||
from bigchaindb.crypto import generate_key_pair
|
||||
from bigchaindb import crypto
|
||||
|
||||
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
@ -48,13 +49,15 @@ def run_configure(args, skip_if_exists=False):
|
||||
return
|
||||
|
||||
# Patch the default configuration with the new values
|
||||
conf = bigchaindb._config
|
||||
print('Generating keypair')
|
||||
conf['keypair']['private'], conf['keypair']['public'] = generate_key_pair()
|
||||
conf = copy.deepcopy(bigchaindb._config)
|
||||
|
||||
for key in ('host', 'port', 'name'):
|
||||
val = conf['database'][key]
|
||||
conf['database'][key] = input('Database {}? (default `{}`): '.format(key, val)) or val
|
||||
print('Generating keypair')
|
||||
conf['keypair']['private'], conf['keypair']['public'] = crypto.generate_key_pair()
|
||||
|
||||
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
|
||||
|
||||
for key in ('host', 'port', 'rate'):
|
||||
val = conf['statsd'][key]
|
||||
|
1
setup.py
1
setup.py
@ -14,6 +14,7 @@ tests_require = [
|
||||
'pylint',
|
||||
'pytest',
|
||||
'pytest-cov',
|
||||
'pytest-xdist',
|
||||
]
|
||||
|
||||
dev_require = [
|
||||
|
@ -6,12 +6,16 @@ Tasks:
|
||||
2. delete test database after running the tests
|
||||
"""
|
||||
|
||||
import os
|
||||
|
||||
import pytest
|
||||
|
||||
|
||||
DB_NAME = 'bigchain_test_{}'.format(os.getpid())
|
||||
|
||||
config = {
|
||||
'database': {
|
||||
'name': 'bigchain_test'
|
||||
'name': DB_NAME
|
||||
},
|
||||
'keypair': {
|
||||
'private': '3i2FDXp87N9ExXSvWxqBAw9EgzoxxGTQNKbtxmWBpTyL',
|
||||
@ -30,7 +34,7 @@ def restore_config(request, node_config):
|
||||
config_utils.dict_config(node_config)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@pytest.fixture(scope='module')
|
||||
def node_config():
|
||||
return config
|
||||
|
||||
|
@ -13,9 +13,6 @@ from bigchaindb import Bigchain
|
||||
from bigchaindb.db import get_conn
|
||||
|
||||
|
||||
NOOP = None
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def restore_config(request, node_config):
|
||||
from bigchaindb import config_utils
|
||||
@ -23,58 +20,60 @@ def restore_config(request, node_config):
|
||||
|
||||
|
||||
@pytest.fixture(scope='module', autouse=True)
|
||||
def setup_database(request):
|
||||
def setup_database(request, node_config):
|
||||
print('Initializing test db')
|
||||
db_name = node_config['database']['name']
|
||||
get_conn().repl()
|
||||
try:
|
||||
r.db_create('bigchain_test').run()
|
||||
r.db_create(db_name).run()
|
||||
except r.ReqlOpFailedError as e:
|
||||
if e.message == 'Database `bigchain_test` already exists.':
|
||||
r.db_drop('bigchain_test').run()
|
||||
r.db_create('bigchain_test').run()
|
||||
if e.message == 'Database `{}` already exists.'.format(db_name):
|
||||
r.db_drop(db_name).run()
|
||||
r.db_create(db_name).run()
|
||||
else:
|
||||
raise
|
||||
|
||||
print('Finished initializing test db')
|
||||
|
||||
# setup tables
|
||||
r.db('bigchain_test').table_create('bigchain').run()
|
||||
r.db('bigchain_test').table_create('backlog').run()
|
||||
r.db(db_name).table_create('bigchain').run()
|
||||
r.db(db_name).table_create('backlog').run()
|
||||
# create the secondary indexes
|
||||
# to order blocks by timestamp
|
||||
r.db('bigchain_test').table('bigchain').index_create('block_timestamp', r.row['block']['timestamp']).run()
|
||||
r.db(db_name).table('bigchain').index_create('block_timestamp', r.row['block']['timestamp']).run()
|
||||
# to order blocks by block number
|
||||
r.db('bigchain_test').table('bigchain').index_create('block_number', r.row['block']['block_number']).run()
|
||||
r.db(db_name).table('bigchain').index_create('block_number', r.row['block']['block_number']).run()
|
||||
# to order transactions by timestamp
|
||||
r.db('bigchain_test').table('backlog').index_create('transaction_timestamp', r.row['transaction']['timestamp']).run()
|
||||
r.db(db_name).table('backlog').index_create('transaction_timestamp', r.row['transaction']['timestamp']).run()
|
||||
# compound index to read transactions from the backlog per assignee
|
||||
r.db('bigchain_test').table('backlog')\
|
||||
r.db(db_name).table('backlog')\
|
||||
.index_create('assignee__transaction_timestamp', [r.row['assignee'], r.row['transaction']['timestamp']])\
|
||||
.run()
|
||||
|
||||
def fin():
|
||||
print('Deleting `bigchain_test` database')
|
||||
print('Deleting `{}` database'.format(db_name))
|
||||
get_conn().repl()
|
||||
try:
|
||||
r.db_drop('bigchain_test').run()
|
||||
r.db_drop(db_name).run()
|
||||
except r.ReqlOpFailedError as e:
|
||||
if e.message != 'Database `bigchain_test` does not exist.':
|
||||
if e.message != 'Database `{}` does not exist.'.format(db_name):
|
||||
raise
|
||||
|
||||
print('Finished deleting `bigchain_test`')
|
||||
print('Finished deleting `{}`'.format(db_name))
|
||||
|
||||
request.addfinalizer(fin)
|
||||
|
||||
|
||||
@pytest.fixture(scope='function', autouse=True)
|
||||
def cleanup_tables(request):
|
||||
def cleanup_tables(request, node_config):
|
||||
db_name = node_config['database']['name']
|
||||
def fin():
|
||||
get_conn().repl()
|
||||
try:
|
||||
r.db('bigchain_test').table('bigchain').delete().run()
|
||||
r.db('bigchain_test').table('backlog').delete().run()
|
||||
r.db(db_name).table('bigchain').delete().run()
|
||||
r.db(db_name).table('backlog').delete().run()
|
||||
except r.ReqlOpFailedError as e:
|
||||
if e.message != 'Database `bigchain_test` does not exist.':
|
||||
if e.message != 'Database `{}` does not exist.'.format(db_name):
|
||||
raise
|
||||
|
||||
request.addfinalizer(fin)
|
||||
|
@ -11,8 +11,8 @@ from .conftest import setup_database as _setup_database
|
||||
# Since we are testing database initialization and database drop,
|
||||
# we need to use the `setup_database` fixture on a function level
|
||||
@pytest.fixture(scope='function', autouse=True)
|
||||
def setup_database(request):
|
||||
_setup_database(request)
|
||||
def setup_database(request, node_config):
|
||||
_setup_database(request, node_config)
|
||||
|
||||
|
||||
def test_init_creates_db_tables_and_indexes():
|
||||
|
@ -1,5 +1,6 @@
|
||||
from argparse import Namespace
|
||||
from pprint import pprint
|
||||
import copy
|
||||
|
||||
import pytest
|
||||
|
||||
@ -51,8 +52,7 @@ def mock_rethink_db_drop(monkeypatch):
|
||||
|
||||
@pytest.fixture
|
||||
def mock_generate_key_pair(monkeypatch):
|
||||
from bigchaindb import crypto
|
||||
monkeypatch.setattr(crypto, 'generate_key_pair', lambda: ('privkey', 'pubkey'))
|
||||
monkeypatch.setattr('bigchaindb.crypto.generate_key_pair', lambda: ('privkey', 'pubkey'))
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@ -71,6 +71,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
|
||||
|
Loading…
x
Reference in New Issue
Block a user