mirror of
https://github.com/bigchaindb/bigchaindb.git
synced 2024-10-13 13:34:05 +00:00
Tests for loading consensus plugins
This commit is contained in:
parent
7253e96796
commit
ad535c7895
@ -15,6 +15,7 @@ def config(request, monkeypatch):
|
|||||||
},
|
},
|
||||||
'keyring': [],
|
'keyring': [],
|
||||||
'CONFIGURED': True,
|
'CONFIGURED': True,
|
||||||
|
'consensus_plugin': 'default'
|
||||||
}
|
}
|
||||||
|
|
||||||
monkeypatch.setattr('bigchaindb.config', config)
|
monkeypatch.setattr('bigchaindb.config', config)
|
||||||
@ -24,6 +25,7 @@ def config(request, monkeypatch):
|
|||||||
|
|
||||||
def test_bigchain_class_default_initialization(config):
|
def test_bigchain_class_default_initialization(config):
|
||||||
from bigchaindb.core import Bigchain
|
from bigchaindb.core import Bigchain
|
||||||
|
from bigchaindb.consensus import BaseConsensusRules
|
||||||
bigchain = Bigchain()
|
bigchain = Bigchain()
|
||||||
assert bigchain.host == config['database']['host']
|
assert bigchain.host == config['database']['host']
|
||||||
assert bigchain.port == config['database']['port']
|
assert bigchain.port == config['database']['port']
|
||||||
@ -31,11 +33,13 @@ def test_bigchain_class_default_initialization(config):
|
|||||||
assert bigchain.me == config['keypair']['public']
|
assert bigchain.me == config['keypair']['public']
|
||||||
assert bigchain.me_private == config['keypair']['private']
|
assert bigchain.me_private == config['keypair']['private']
|
||||||
assert bigchain.federation_nodes == config['keyring']
|
assert bigchain.federation_nodes == config['keyring']
|
||||||
|
assert bigchain.consensus == BaseConsensusRules
|
||||||
assert bigchain._conn is None
|
assert bigchain._conn is None
|
||||||
|
|
||||||
|
|
||||||
def test_bigchain_class_initialization_with_parameters(config):
|
def test_bigchain_class_initialization_with_parameters(config):
|
||||||
from bigchaindb.core import Bigchain
|
from bigchaindb.core import Bigchain
|
||||||
|
from bigchaindb.consensus import BaseConsensusRules
|
||||||
init_kwargs = {
|
init_kwargs = {
|
||||||
'host': 'some_node',
|
'host': 'some_node',
|
||||||
'port': '12345',
|
'port': '12345',
|
||||||
@ -43,6 +47,7 @@ def test_bigchain_class_initialization_with_parameters(config):
|
|||||||
'public_key': 'white',
|
'public_key': 'white',
|
||||||
'private_key': 'black',
|
'private_key': 'black',
|
||||||
'keyring': ['key_one', 'key_two'],
|
'keyring': ['key_one', 'key_two'],
|
||||||
|
'consensus_plugin': 'default'
|
||||||
}
|
}
|
||||||
bigchain = Bigchain(**init_kwargs)
|
bigchain = Bigchain(**init_kwargs)
|
||||||
assert bigchain.host == init_kwargs['host']
|
assert bigchain.host == init_kwargs['host']
|
||||||
@ -51,4 +56,5 @@ def test_bigchain_class_initialization_with_parameters(config):
|
|||||||
assert bigchain.me == init_kwargs['public_key']
|
assert bigchain.me == init_kwargs['public_key']
|
||||||
assert bigchain.me_private == init_kwargs['private_key']
|
assert bigchain.me_private == init_kwargs['private_key']
|
||||||
assert bigchain.federation_nodes == init_kwargs['keyring']
|
assert bigchain.federation_nodes == init_kwargs['keyring']
|
||||||
|
assert bigchain.consensus == BaseConsensusRules
|
||||||
assert bigchain._conn is None
|
assert bigchain._conn is None
|
||||||
|
@ -37,3 +37,32 @@ def test_bigchain_instance_raises_when_not_configured(monkeypatch):
|
|||||||
|
|
||||||
with pytest.raises(exceptions.KeypairNotFoundException):
|
with pytest.raises(exceptions.KeypairNotFoundException):
|
||||||
bigchaindb.Bigchain()
|
bigchaindb.Bigchain()
|
||||||
|
|
||||||
|
|
||||||
|
def test_load_consensus_plugin_loads_default_rules_without_name():
|
||||||
|
from bigchaindb import config_utils
|
||||||
|
from bigchaindb.consensus import BaseConsensusRules
|
||||||
|
|
||||||
|
assert config_utils.load_consensus_plugin() == BaseConsensusRules
|
||||||
|
|
||||||
|
|
||||||
|
def test_load_consensus_plugin_raises_with_unknown_name():
|
||||||
|
from pkg_resources import ResolutionError
|
||||||
|
from bigchaindb import config_utils
|
||||||
|
|
||||||
|
with pytest.raises(ResolutionError):
|
||||||
|
config_utils.load_consensus_plugin('bogus')
|
||||||
|
|
||||||
|
|
||||||
|
def test_load_consensus_plugin_raises_with_invalid_subclass(monkeypatch):
|
||||||
|
# Monkeypatch entry_point.load to return something other than a
|
||||||
|
# ConsensusRules instance
|
||||||
|
from bigchaindb import config_utils
|
||||||
|
monkeypatch.setattr(config_utils,
|
||||||
|
'iter_entry_points',
|
||||||
|
lambda *args: [ type('entry_point',
|
||||||
|
(object),
|
||||||
|
{'load': lambda: object}) ])
|
||||||
|
|
||||||
|
with pytest.raises(TypeError):
|
||||||
|
config_utils.load_consensus_plugin()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user