mirror of
https://github.com/bigchaindb/bigchaindb.git
synced 2024-10-13 13:34:05 +00:00
merge test_schema tests and tweak Data Models documentation index
This commit is contained in:
parent
624a0c972a
commit
94df6fc00a
@ -16,4 +16,4 @@ This section unpacks each one in turn.
|
||||
asset-model
|
||||
crypto-conditions
|
||||
block-model
|
||||
The Vote Model <../schema/vote>
|
||||
../schema/vote
|
||||
|
@ -1,4 +1,5 @@
|
||||
from bigchaindb.common.schema import TX_SCHEMA, VOTE_SCHEMA
|
||||
from bigchaindb.common.schema import TX_SCHEMA, VOTE_SCHEMA, \
|
||||
drop_schema_descriptions
|
||||
|
||||
|
||||
def _test_additionalproperties(node, path=''):
|
||||
@ -23,3 +24,46 @@ def test_transaction_schema_additionalproperties():
|
||||
|
||||
def test_vote_schema_additionalproperties():
|
||||
_test_additionalproperties(VOTE_SCHEMA)
|
||||
|
||||
|
||||
def test_drop_descriptions():
|
||||
node = {
|
||||
'description': 'abc',
|
||||
'properties': {
|
||||
'description': {
|
||||
'description': ('The property named "description" should stay'
|
||||
'but description meta field goes'),
|
||||
},
|
||||
'properties': {
|
||||
'description': 'this must go'
|
||||
},
|
||||
'any': {
|
||||
'anyOf': [
|
||||
{
|
||||
'description': 'must go'
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
'definitions': {
|
||||
'wat': {
|
||||
'description': "go"
|
||||
}
|
||||
}
|
||||
}
|
||||
drop_schema_descriptions(node)
|
||||
expected = {
|
||||
'properties': {
|
||||
'description': {},
|
||||
'properties': {},
|
||||
'any': {
|
||||
'anyOf': [
|
||||
{}
|
||||
]
|
||||
}
|
||||
},
|
||||
'definitions': {
|
||||
'wat': {},
|
||||
}
|
||||
}
|
||||
assert node == expected
|
||||
|
@ -1,69 +0,0 @@
|
||||
from bigchaindb.common.schema import TX_SCHEMA, VOTE_SCHEMA, \
|
||||
drop_schema_descriptions
|
||||
|
||||
|
||||
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)
|
||||
|
||||
|
||||
def test_drop_descriptions():
|
||||
node = {
|
||||
'description': 'abc',
|
||||
'properties': {
|
||||
'description': {
|
||||
'description': ('The property named "description" should stay'
|
||||
'but description meta field goes'),
|
||||
},
|
||||
'properties': {
|
||||
'description': 'this must go'
|
||||
},
|
||||
'any': {
|
||||
'anyOf': [
|
||||
{
|
||||
'description': 'must go'
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
'definitions': {
|
||||
'wat': {
|
||||
'description': "go"
|
||||
}
|
||||
}
|
||||
}
|
||||
drop_schema_descriptions(node)
|
||||
expected = {
|
||||
'properties': {
|
||||
'description': {},
|
||||
'properties': {},
|
||||
'any': {
|
||||
'anyOf': [
|
||||
{}
|
||||
]
|
||||
}
|
||||
},
|
||||
'definitions': {
|
||||
'wat': {},
|
||||
}
|
||||
}
|
||||
assert node == expected
|
Loading…
x
Reference in New Issue
Block a user