From 0c35e9abff7692b1e1170c150859d5a310a82eba Mon Sep 17 00:00:00 2001 From: vrde Date: Wed, 8 Jun 2016 09:39:40 -0700 Subject: [PATCH] Return 404 when tx not found --- bigchaindb/web/views.py | 5 ++++- tests/web/test_basic_views.py | 6 ++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/bigchaindb/web/views.py b/bigchaindb/web/views.py index 3199ac59..608adb51 100644 --- a/bigchaindb/web/views.py +++ b/bigchaindb/web/views.py @@ -5,7 +5,7 @@ For more information please refer to the documentation in Apiary: """ import flask -from flask import current_app, request, Blueprint +from flask import abort, current_app, request, Blueprint import bigchaindb from bigchaindb import util @@ -51,6 +51,9 @@ def get_transaction(tx_id): with pool() as bigchain: tx = bigchain.get_transaction(tx_id) + if not tx: + abort(404) + return flask.jsonify(**tx) diff --git a/tests/web/test_basic_views.py b/tests/web/test_basic_views.py index 2cae71c2..4e47a638 100644 --- a/tests/web/test_basic_views.py +++ b/tests/web/test_basic_views.py @@ -16,6 +16,12 @@ def test_get_transaction_endpoint(b, client, user_vk): assert tx == res.json +@pytest.mark.usefixtures('inputs') +def test_get_transaction_returns_404_if_not_found(client): + res = client.get(TX_ENDPOINT + '123') + assert res.status_code == 404 + + def test_post_create_transaction_endpoint(b, client): keypair = crypto.generate_key_pair()