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 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
|
# 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.pie.objects import ManagedObject
class DummyManagedObject(ManagedObject):
"""
A dummy ManagedObject subclass for testing purposes.
"""
def __init__(self, object_type=None):
"""
Create a DummyManagedObject
Args:
object_type (any): A value to test the setting of the object_type
attribute. Optional, defaults to None.
"""
super(DummyManagedObject, self).__init__()
self._object_type = object_type
def validate(self):
super(DummyManagedObject, self).validate()
return
def __repr__(self):
super(DummyManagedObject, self).__repr__()
return ''
def __str__(self):
super(DummyManagedObject, self).__str__()
return ''
def __eq__(self, other):
super(DummyManagedObject, self).__eq__(other)
return True
def __ne__(self, other):
super(DummyManagedObject, self).__ne__(other)
return False
class TestManagedObject(TestCase):
"""
Test suite for ManagedObject.
Since ManagedObject is an ABC abstract class, all tests are run against a
dummy subclass defined above, DummyManagedObject.
"""
def setUp(self):
super(TestManagedObject, self).setUp()
def tearDown(self):
super(TestManagedObject, self).tearDown()
def test_init(self):
"""
Test that a complete subclass of ManagedObject can be instantiated.
"""
DummyManagedObject()
def test_get_object_type(self):
"""
Test that the object type can be retrieved from the ManagedObject.
"""
expected = 'dummy'
dummy = DummyManagedObject(expected)
observed = dummy.object_type
self.assertEqual(expected, observed)
def test_set_object_type(self):
"""
Test that an AttributeError is raised when attempting to change the
value of the object type.
"""
dummy = DummyManagedObject()
def set_object_type():
dummy.object_type = 'placeholder'
self.assertRaises(AttributeError, set_object_type)
def test_validate(self):
"""
Test that validate can be called on a ManagedObject.
"""
dummy = DummyManagedObject()
dummy.validate()
def test_repr(self):
"""
Test that repr can be applied to a ManagedObject.
"""
dummy = DummyManagedObject()
repr(dummy)
def test_str(self):
"""
Test that str can be applied to a ManagedObject.
"""
dummy = DummyManagedObject()
str(dummy)
def test_eq(self):
"""
Test that equality can be applied to a ManagedObject.
"""
dummy = DummyManagedObject()
self.assertTrue(dummy == dummy)
def test_ne(self):
"""
Test that inequality can be applied to a ManagedObject.
"""
dummy = DummyManagedObject()
self.assertFalse(dummy != dummy)
|