From 16d79283f298f1728fce4643a57385179a7729e9 Mon Sep 17 00:00:00 2001 From: Hao Shen Date: Tue, 4 Apr 2017 11:36:05 -0700 Subject: [PATCH] Modify KmipOperationFailure to expose status/reason/message attributes --- kmip/pie/exceptions.py | 6 +++++- kmip/tests/unit/pie/test_exceptions.py | 7 +++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/kmip/pie/exceptions.py b/kmip/pie/exceptions.py index 3516047..27e845d 100644 --- a/kmip/pie/exceptions.py +++ b/kmip/pie/exceptions.py @@ -39,7 +39,8 @@ class KmipOperationFailure(Exception): """ 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: status: a ResultStatus enumeration @@ -48,3 +49,6 @@ class KmipOperationFailure(Exception): """ msg = "{0}: {1} - {2}".format(status.name, reason.name, message) super(KmipOperationFailure, self).__init__(msg) + self.status = status + self.reason = reason + self.message = message diff --git a/kmip/tests/unit/pie/test_exceptions.py b/kmip/tests/unit/pie/test_exceptions.py index ea56e26..8f2fe92 100644 --- a/kmip/tests/unit/pie/test_exceptions.py +++ b/kmip/tests/unit/pie/test_exceptions.py @@ -93,8 +93,8 @@ class TestKmipOperationFailure(TestCase): def test_message(self): """ - Test that a KmipOperationFailure exception message can be set - properly. + Test that a KmipOperationFailure exception message and attributes can + be set properly. """ status = ResultStatus.OPERATION_FAILED reason = ResultReason.GENERAL_FAILURE @@ -104,3 +104,6 @@ class TestKmipOperationFailure(TestCase): status.name, reason.name, "Test error message.") self.assertEqual(msg, str(exc)) + self.assertEqual(status, exc.status) + self.assertEqual(reason, exc.reason) + self.assertEqual("Test error message.", exc.message)