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
|
before_script: rethinkdb --daemon
|
||||||
|
|
||||||
script: py.test -v --cov=bigchaindb
|
script: py.test -n8 -v --cov=bigchaindb
|
||||||
|
|
||||||
after_success: codecov
|
after_success: codecov
|
||||||
|
@ -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
|
||||||
@ -11,7 +12,7 @@ from bigchaindb import db
|
|||||||
from bigchaindb.exceptions import DatabaseAlreadyExists
|
from bigchaindb.exceptions import DatabaseAlreadyExists
|
||||||
from bigchaindb.commands.utils import base_parser, start
|
from bigchaindb.commands.utils import base_parser, start
|
||||||
from bigchaindb.processes import Processes
|
from bigchaindb.processes import Processes
|
||||||
from bigchaindb.crypto import generate_key_pair
|
from bigchaindb import crypto
|
||||||
|
|
||||||
|
|
||||||
logging.basicConfig(level=logging.INFO)
|
logging.basicConfig(level=logging.INFO)
|
||||||
@ -48,10 +49,12 @@ 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')
|
|
||||||
conf['keypair']['private'], conf['keypair']['public'] = generate_key_pair()
|
|
||||||
|
|
||||||
|
print('Generating keypair')
|
||||||
|
conf['keypair']['private'], conf['keypair']['public'] = crypto.generate_key_pair()
|
||||||
|
|
||||||
|
if not args.yes:
|
||||||
for key in ('host', 'port', 'name'):
|
for key in ('host', 'port', 'name'):
|
||||||
val = conf['database'][key]
|
val = conf['database'][key]
|
||||||
conf['database'][key] = input('Database {}? (default `{}`): '.format(key, val)) or val
|
conf['database'][key] = input('Database {}? (default `{}`): '.format(key, val)) or val
|
||||||
|
1
setup.py
1
setup.py
@ -14,6 +14,7 @@ tests_require = [
|
|||||||
'pylint',
|
'pylint',
|
||||||
'pytest',
|
'pytest',
|
||||||
'pytest-cov',
|
'pytest-cov',
|
||||||
|
'pytest-xdist',
|
||||||
]
|
]
|
||||||
|
|
||||||
dev_require = [
|
dev_require = [
|
||||||
|
@ -6,12 +6,16 @@ Tasks:
|
|||||||
2. delete test database after running the tests
|
2. delete test database after running the tests
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import os
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
|
||||||
|
DB_NAME = 'bigchain_test_{}'.format(os.getpid())
|
||||||
|
|
||||||
config = {
|
config = {
|
||||||
'database': {
|
'database': {
|
||||||
'name': 'bigchain_test'
|
'name': DB_NAME
|
||||||
},
|
},
|
||||||
'keypair': {
|
'keypair': {
|
||||||
'private': '3i2FDXp87N9ExXSvWxqBAw9EgzoxxGTQNKbtxmWBpTyL',
|
'private': '3i2FDXp87N9ExXSvWxqBAw9EgzoxxGTQNKbtxmWBpTyL',
|
||||||
@ -30,7 +34,7 @@ def restore_config(request, node_config):
|
|||||||
config_utils.dict_config(node_config)
|
config_utils.dict_config(node_config)
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture(scope='module')
|
||||||
def node_config():
|
def node_config():
|
||||||
return config
|
return config
|
||||||
|
|
||||||
|
@ -13,9 +13,6 @@ from bigchaindb import Bigchain
|
|||||||
from bigchaindb.db import get_conn
|
from bigchaindb.db import get_conn
|
||||||
|
|
||||||
|
|
||||||
NOOP = None
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(autouse=True)
|
@pytest.fixture(autouse=True)
|
||||||
def restore_config(request, node_config):
|
def restore_config(request, node_config):
|
||||||
from bigchaindb import config_utils
|
from bigchaindb import config_utils
|
||||||
@ -23,58 +20,60 @@ def restore_config(request, node_config):
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope='module', autouse=True)
|
@pytest.fixture(scope='module', autouse=True)
|
||||||
def setup_database(request):
|
def setup_database(request, node_config):
|
||||||
print('Initializing test db')
|
print('Initializing test db')
|
||||||
|
db_name = node_config['database']['name']
|
||||||
get_conn().repl()
|
get_conn().repl()
|
||||||
try:
|
try:
|
||||||
r.db_create('bigchain_test').run()
|
r.db_create(db_name).run()
|
||||||
except r.ReqlOpFailedError as e:
|
except r.ReqlOpFailedError as e:
|
||||||
if e.message == 'Database `bigchain_test` already exists.':
|
if e.message == 'Database `{}` already exists.'.format(db_name):
|
||||||
r.db_drop('bigchain_test').run()
|
r.db_drop(db_name).run()
|
||||||
r.db_create('bigchain_test').run()
|
r.db_create(db_name).run()
|
||||||
else:
|
else:
|
||||||
raise
|
raise
|
||||||
|
|
||||||
print('Finished initializing test db')
|
print('Finished initializing test db')
|
||||||
|
|
||||||
# setup tables
|
# setup tables
|
||||||
r.db('bigchain_test').table_create('bigchain').run()
|
r.db(db_name).table_create('bigchain').run()
|
||||||
r.db('bigchain_test').table_create('backlog').run()
|
r.db(db_name).table_create('backlog').run()
|
||||||
# create the secondary indexes
|
# create the secondary indexes
|
||||||
# to order blocks by timestamp
|
# 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
|
# 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
|
# 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
|
# 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']])\
|
.index_create('assignee__transaction_timestamp', [r.row['assignee'], r.row['transaction']['timestamp']])\
|
||||||
.run()
|
.run()
|
||||||
|
|
||||||
def fin():
|
def fin():
|
||||||
print('Deleting `bigchain_test` database')
|
print('Deleting `{}` database'.format(db_name))
|
||||||
get_conn().repl()
|
get_conn().repl()
|
||||||
try:
|
try:
|
||||||
r.db_drop('bigchain_test').run()
|
r.db_drop(db_name).run()
|
||||||
except r.ReqlOpFailedError as e:
|
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
|
raise
|
||||||
|
|
||||||
print('Finished deleting `bigchain_test`')
|
print('Finished deleting `{}`'.format(db_name))
|
||||||
|
|
||||||
request.addfinalizer(fin)
|
request.addfinalizer(fin)
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope='function', autouse=True)
|
@pytest.fixture(scope='function', autouse=True)
|
||||||
def cleanup_tables(request):
|
def cleanup_tables(request, node_config):
|
||||||
|
db_name = node_config['database']['name']
|
||||||
def fin():
|
def fin():
|
||||||
get_conn().repl()
|
get_conn().repl()
|
||||||
try:
|
try:
|
||||||
r.db('bigchain_test').table('bigchain').delete().run()
|
r.db(db_name).table('bigchain').delete().run()
|
||||||
r.db('bigchain_test').table('backlog').delete().run()
|
r.db(db_name).table('backlog').delete().run()
|
||||||
except r.ReqlOpFailedError as e:
|
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
|
raise
|
||||||
|
|
||||||
request.addfinalizer(fin)
|
request.addfinalizer(fin)
|
||||||
|
@ -11,8 +11,8 @@ from .conftest import setup_database as _setup_database
|
|||||||
# Since we are testing database initialization and database drop,
|
# Since we are testing database initialization and database drop,
|
||||||
# we need to use the `setup_database` fixture on a function level
|
# we need to use the `setup_database` fixture on a function level
|
||||||
@pytest.fixture(scope='function', autouse=True)
|
@pytest.fixture(scope='function', autouse=True)
|
||||||
def setup_database(request):
|
def setup_database(request, node_config):
|
||||||
_setup_database(request)
|
_setup_database(request, node_config)
|
||||||
|
|
||||||
|
|
||||||
def test_init_creates_db_tables_and_indexes():
|
def test_init_creates_db_tables_and_indexes():
|
||||||
|
@ -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
|
||||||
|
|
||||||
@ -51,8 +52,7 @@ def mock_rethink_db_drop(monkeypatch):
|
|||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def mock_generate_key_pair(monkeypatch):
|
def mock_generate_key_pair(monkeypatch):
|
||||||
from bigchaindb import crypto
|
monkeypatch.setattr('bigchaindb.crypto.generate_key_pair', lambda: ('privkey', 'pubkey'))
|
||||||
monkeypatch.setattr(crypto, 'generate_key_pair', lambda: ('privkey', 'pubkey'))
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
@ -71,6 +71,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