error case for find_role

This commit is contained in:
James Prestwich 2017-09-04 18:56:48 -06:00
parent ba1119570b
commit 5604b1b064
No known key found for this signature in database
GPG Key ID: 519E010A79028CCC
2 changed files with 19 additions and 1 deletions

View File

@ -181,7 +181,10 @@ def find_role(contract):
else:
return 'initiator'
else:
return 'fulfiller'
if protocol.is_myaddr(contract.fulfiller):
return 'fulfiller'
else:
raise ValueError('You are not a participant in this contract.')
def checktrade(tradeid):

View File

@ -70,6 +70,21 @@ class TestCLI(unittest.TestCase):
self.assertEqual(res, 'fulfiller')
@mock.patch('xcat.cli.Protocol')
def test_find_role_error(self, mock_protocol):
mock_protocol().is_myaddr = lambda k: k == 'me'
test_contract = mock.MagicMock()
test_contract.initiator = 'you'
test_contract.fulfiller = 'you'
with self.assertRaises(ValueError) as context:
cli.find_role(test_contract)
self.assertTrue(
'You are not a participant in this contract.'
in str(context.exception))
def test_checktrade(self):
pass