Add to_uri for TransactionLink

This commit is contained in:
tim 2016-11-15 11:37:47 +01:00 committed by Sylvain Bellemare
parent d8256d50f2
commit f78c90ada8
2 changed files with 24 additions and 0 deletions

View File

@ -189,6 +189,12 @@ class TransactionLink(object):
'cid': self.cid,
}
def to_uri(self, path=''):
if self.txid is None and self.cid is None:
return None
return '{}/transactions/{}/conditions/{}'.format(path, self.txid,
self.cid)
class Condition(object):
"""A Condition is used to lock an asset.

View File

@ -428,6 +428,24 @@ def test_transaction_link_deserialization_with_empty_payload():
assert tx_link == expected
def test_transaction_link_empty_to_uri():
from bigchaindb.common.transaction import TransactionLink
expected = None
tx_link = TransactionLink().to_uri()
assert expected == tx_link
def test_transaction_link_to_uri():
from bigchaindb.common.transaction import TransactionLink
expected = 'path/transactions/abc/conditions/0'
tx_link = TransactionLink('abc', 0).to_uri('path')
assert expected == tx_link
def test_cast_transaction_link_to_boolean():
from bigchaindb.common.transaction import TransactionLink