From 855dc7a5e8885c26bb6a96842459ade2ffb2b137 Mon Sep 17 00:00:00 2001 From: Scott Sadler Date: Thu, 24 Nov 2016 16:37:26 +0100 Subject: [PATCH] refactor schema __init__ slightly --- bigchaindb/common/schema/__init__.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/bigchaindb/common/schema/__init__.py b/bigchaindb/common/schema/__init__.py index a49495f9..89a6a820 100644 --- a/bigchaindb/common/schema/__init__.py +++ b/bigchaindb/common/schema/__init__.py @@ -23,15 +23,20 @@ def _validate_schema(schema, body): TX_SCHEMA_PATH, TX_SCHEMA = _load_schema('transaction') + + +def validate_transaction_schema(tx): + """ Validate a transaction dict """ + _validate_schema(TX_SCHEMA, tx) + + VOTE_SCHEMA_PATH, VOTE_SCHEMA = _load_schema('vote') -def validate_transaction_schema(tx_body): - """ Validate a transaction dict """ - _validate_schema(TX_SCHEMA, tx_body) - - -def validate_vote_schema(tx_body): +def validate_vote_schema(vote): """ Validate a vote dict """ - _validate_schema(VOTE_SCHEMA, tx_body) - + # A vote does not have an ID, but the database may add one. + if 'id' in vote: + vote = dict(vote) + del vote['id'] + _validate_schema(VOTE_SCHEMA, vote)