mirror of
https://github.com/bigchaindb/bigchaindb.git
synced 2024-10-13 13:34:05 +00:00
refactor schema tests into separate modules
This commit is contained in:
parent
44a43dcf94
commit
bfb5be3ba4
25
tests/common/schema/test_schema.py
Normal file
25
tests/common/schema/test_schema.py
Normal file
@ -0,0 +1,25 @@
|
||||
from bigchaindb.common.schema import TX_SCHEMA, VOTE_SCHEMA
|
||||
|
||||
|
||||
def _test_additionalproperties(node, path=''):
|
||||
"""
|
||||
Validate that each object node has additionalProperties set, so that
|
||||
objects with junk keys do not pass as valid.
|
||||
"""
|
||||
if isinstance(node, list):
|
||||
for i, nnode in enumerate(node):
|
||||
_test_additionalproperties(nnode, path + str(i) + '.')
|
||||
if isinstance(node, dict):
|
||||
if node.get('type') == 'object':
|
||||
assert 'additionalProperties' in node, \
|
||||
("additionalProperties not set at path:" + path)
|
||||
for name, val in node.items():
|
||||
_test_additionalproperties(val, path + name + '.')
|
||||
|
||||
|
||||
def test_transaction_schema_additionalproperties():
|
||||
_test_additionalproperties(TX_SCHEMA)
|
||||
|
||||
|
||||
def test_vote_schema_additionalproperties():
|
||||
_test_additionalproperties(VOTE_SCHEMA)
|
@ -1,7 +1,7 @@
|
||||
from pytest import raises
|
||||
|
||||
from bigchaindb.common.exceptions import SchemaValidationError
|
||||
from bigchaindb.common.schema import TX_SCHEMA, validate_transaction_schema
|
||||
from bigchaindb.common.schema import validate_transaction_schema
|
||||
|
||||
|
||||
def test_validate_transaction_create(create_tx):
|
||||
@ -16,6 +16,11 @@ def test_validate_transaction_signed_transfer(signed_transfer_tx):
|
||||
validate_transaction_schema(signed_transfer_tx.to_dict())
|
||||
|
||||
|
||||
def test_validate_transaction_fails():
|
||||
with raises(SchemaValidationError):
|
||||
validate_transaction_schema({})
|
||||
|
||||
|
||||
def test_validate_fails_metadata_empty_dict(create_tx):
|
||||
create_tx.metadata = {'a': 1}
|
||||
validate_transaction_schema(create_tx.to_dict())
|
||||
@ -24,27 +29,3 @@ def test_validate_fails_metadata_empty_dict(create_tx):
|
||||
create_tx.metadata = {}
|
||||
with raises(SchemaValidationError):
|
||||
validate_transaction_schema(create_tx.to_dict())
|
||||
|
||||
|
||||
def test_validation_fails():
|
||||
with raises(SchemaValidationError):
|
||||
validate_transaction_schema({})
|
||||
|
||||
|
||||
def test_addition_properties_always_set():
|
||||
"""
|
||||
Validate that each object node has additionalProperties set, so that
|
||||
transactions with junk keys do not pass as valid.
|
||||
"""
|
||||
def walk(node, path=''):
|
||||
if isinstance(node, list):
|
||||
for i, nnode in enumerate(node):
|
||||
walk(nnode, path + str(i) + '.')
|
||||
if isinstance(node, dict):
|
||||
if node.get('type') == 'object':
|
||||
assert 'additionalProperties' in node, \
|
||||
("additionalProperties not set at path:" + path)
|
||||
for name, val in node.items():
|
||||
walk(val, path + name + '.')
|
||||
|
||||
walk(TX_SCHEMA)
|
0
tests/common/schema/test_vote_schema.py
Normal file
0
tests/common/schema/test_vote_schema.py
Normal file
Loading…
x
Reference in New Issue
Block a user