1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
|
# Copyright (c) 2015 The Johns Hopkins University/Applied Physics Laboratory
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from testtools import TestCase
from kmip.core.enums import ResultStatus
from kmip.core.enums import ResultReason
from kmip.pie.exceptions import ClientConnectionFailure
from kmip.pie.exceptions import ClientConnectionNotOpen
from kmip.pie.exceptions import KmipOperationFailure
class TestClientConnectionFailure(TestCase):
"""
Test suite for ClientConnectionFailure.
"""
def setUp(self):
super(TestClientConnectionFailure, self).setUp()
def tearDown(self):
super(TestClientConnectionFailure, self).tearDown()
def test_init(self):
"""
Test that a ClientConnectionFailure exception can be instantiated.
"""
exc = ClientConnectionFailure()
self.assertIsInstance(exc, Exception)
def test_message(self):
"""
Test that a ClientConnectionFailure exception message can be set
properly.
"""
exc = ClientConnectionFailure("test message")
self.assertEqual("test message", str(exc))
class TestClientConnectionNotOpen(TestCase):
"""
Test suite for ClientConnectionNotOpen.
"""
def setUp(self):
super(TestClientConnectionNotOpen, self).setUp()
def tearDown(self):
super(TestClientConnectionNotOpen, self).tearDown()
def test_init(self):
"""
Test that a ClientConnectionNotOpen exception can be instantiated.
"""
exc = ClientConnectionNotOpen()
self.assertIsInstance(exc, Exception)
self.assertEqual("client connection not open", str(exc))
class TestKmipOperationFailure(TestCase):
"""
Test suite for KmipOperationFailure.
"""
def setUp(self):
super(TestKmipOperationFailure, self).setUp()
def tearDown(self):
super(TestKmipOperationFailure, self).tearDown()
def test_init(self):
"""
Test that a KmipOperationFailure exception can be instantiated.
"""
exc = KmipOperationFailure(
ResultStatus.OPERATION_FAILED,
ResultReason.GENERAL_FAILURE,
"Test error message.")
self.assertIsInstance(exc, Exception)
def test_message(self):
"""
Test that a KmipOperationFailure exception message can be set
properly.
"""
status = ResultStatus.OPERATION_FAILED
reason = ResultReason.GENERAL_FAILURE
exc = KmipOperationFailure(status, reason, "Test error message.")
msg = "{0}: {1} - {2}".format(
status.name, reason.name, "Test error message.")
self.assertEqual(msg, str(exc))
|