Modify KmipOperationFailure to expose status/reason/message attributes

This commit is contained in:
Hao Shen 2017-04-04 11:36:05 -07:00
parent 2aabad714a
commit 16d79283f2
2 changed files with 10 additions and 3 deletions

View File

@ -39,7 +39,8 @@ class KmipOperationFailure(Exception):
""" """
def __init__(self, status, reason, message): def __init__(self, status, reason, message):
""" """
Construct the error message for the KMIP operation failure. Construct the error message and attributes for the KMIP operation
failure.
Args: Args:
status: a ResultStatus enumeration status: a ResultStatus enumeration
@ -48,3 +49,6 @@ class KmipOperationFailure(Exception):
""" """
msg = "{0}: {1} - {2}".format(status.name, reason.name, message) msg = "{0}: {1} - {2}".format(status.name, reason.name, message)
super(KmipOperationFailure, self).__init__(msg) super(KmipOperationFailure, self).__init__(msg)
self.status = status
self.reason = reason
self.message = message

View File

@ -93,8 +93,8 @@ class TestKmipOperationFailure(TestCase):
def test_message(self): def test_message(self):
""" """
Test that a KmipOperationFailure exception message can be set Test that a KmipOperationFailure exception message and attributes can
properly. be set properly.
""" """
status = ResultStatus.OPERATION_FAILED status = ResultStatus.OPERATION_FAILED
reason = ResultReason.GENERAL_FAILURE reason = ResultReason.GENERAL_FAILURE
@ -104,3 +104,6 @@ class TestKmipOperationFailure(TestCase):
status.name, reason.name, "Test error message.") status.name, reason.name, "Test error message.")
self.assertEqual(msg, str(exc)) self.assertEqual(msg, str(exc))
self.assertEqual(status, exc.status)
self.assertEqual(reason, exc.reason)
self.assertEqual("Test error message.", exc.message)