mirror of
https://github.com/bigchaindb/bigchaindb.git
synced 2024-10-13 13:34:05 +00:00
Fix variable type check and docstrings
This commit is contained in:
parent
99aa38b217
commit
a29fd7e84f
@ -108,14 +108,14 @@ def init_database(connection=None, dbname=None):
|
||||
create_indexes(connection, dbname)
|
||||
|
||||
|
||||
def validate_if_exists_language(obj, key):
|
||||
def validate_language_key(obj, key):
|
||||
"""Validate all nested "language" key in `obj`.
|
||||
|
||||
Args:
|
||||
obj (dict): dictonary whose "language" key is to be validated.
|
||||
|
||||
Returns:
|
||||
None: validation successfull
|
||||
None: validation successful
|
||||
|
||||
Raises:
|
||||
ValidationError: raises execption incase language is not valid.
|
||||
@ -135,7 +135,7 @@ def validate_language(value):
|
||||
value (str): language to validated
|
||||
|
||||
Returns:
|
||||
None: validation successfull
|
||||
None: validation successful
|
||||
|
||||
Raises:
|
||||
ValidationError: raises execption incase language is not valid.
|
||||
@ -145,4 +145,4 @@ def validate_language(value):
|
||||
'language "{}". If you do not understand this error '
|
||||
'message then please rename key/field "language" to '
|
||||
'something else like "lang".').format(value)
|
||||
raise ValidationError(error_str) from ValueError()
|
||||
raise ValidationError(error_str)
|
||||
|
@ -92,9 +92,8 @@ def validate_all_keys(obj_name, obj, validation_fun):
|
||||
"""
|
||||
for key, value in obj.items():
|
||||
validation_fun(obj_name, key)
|
||||
if type(value) is dict:
|
||||
if isinstance(value, dict):
|
||||
validate_all_keys(obj_name, value, validation_fun)
|
||||
return
|
||||
|
||||
|
||||
def validate_all_value_for_key(obj, key, validation_fun):
|
||||
@ -107,18 +106,14 @@ def validate_all_value_for_key(obj, key, validation_fun):
|
||||
validation_fun (function): function used to validate the value
|
||||
of `key`.
|
||||
|
||||
Returns:
|
||||
None: indicates validation successfull
|
||||
|
||||
Raises:
|
||||
ValidationError: `validation_fun` will raise this error on failure
|
||||
"""
|
||||
for vkey, value in obj.items():
|
||||
if vkey == key:
|
||||
validation_fun(value)
|
||||
elif type(value) is dict:
|
||||
elif isinstance(value, dict):
|
||||
validate_all_value_for_key(value, key, validation_fun)
|
||||
return
|
||||
|
||||
|
||||
def validate_key(obj_name, key):
|
||||
@ -139,4 +134,4 @@ def validate_key(obj_name, key):
|
||||
error_str = ('Invalid key name "{}" in {} object. The '
|
||||
'key name cannot contain characters '
|
||||
'".", "$" or null characters').format(key, obj_name)
|
||||
raise ValidationError(error_str) from ValueError()
|
||||
raise ValidationError(error_str)
|
||||
|
@ -11,7 +11,7 @@ from bigchaindb.common.transaction import Transaction
|
||||
from bigchaindb.common.utils import (gen_timestamp, serialize,
|
||||
validate_txn_obj, validate_key)
|
||||
from bigchaindb.common.schema import validate_transaction_schema
|
||||
from bigchaindb.backend.schema import validate_if_exists_language
|
||||
from bigchaindb.backend.schema import validate_language_key
|
||||
|
||||
|
||||
class Transaction(Transaction):
|
||||
@ -88,7 +88,7 @@ class Transaction(Transaction):
|
||||
validate_transaction_schema(tx_body)
|
||||
validate_txn_obj('asset', tx_body['asset'], 'data', validate_key)
|
||||
validate_txn_obj('metadata', tx_body, 'metadata', validate_key)
|
||||
validate_if_exists_language(tx_body['asset'], 'data')
|
||||
validate_language_key(tx_body['asset'], 'data')
|
||||
return super().from_dict(tx_body)
|
||||
|
||||
@classmethod
|
||||
|
Loading…
x
Reference in New Issue
Block a user