From ac6d0ae81c5f00030673a94c31a89383d68214af Mon Sep 17 00:00:00 2001 From: Hadi Esiely Date: Mon, 28 Sep 2015 13:05:41 -0400 Subject: [PATCH] Added tests for testing Name attribute Completes test coverage for the Name attribute --- .../unit/core/attributes/test_attributes.py | 55 ++++++++++++++++--- 1 file changed, 47 insertions(+), 8 deletions(-) diff --git a/kmip/tests/unit/core/attributes/test_attributes.py b/kmip/tests/unit/core/attributes/test_attributes.py index 9cbc080..d812eb3 100644 --- a/kmip/tests/unit/core/attributes/test_attributes.py +++ b/kmip/tests/unit/core/attributes/test_attributes.py @@ -21,12 +21,15 @@ from kmip.core.attributes import CertificateType from kmip.core.attributes import DigestValue from kmip.core.attributes import HashingAlgorithm from kmip.core.attributes import OperationPolicyName +from kmip.core.attributes import Name from kmip.core.enums import CertificateTypeEnum from kmip.core.enums import HashingAlgorithm as HashingAlgorithmEnum from kmip.core.utils import BytearrayStream +from kmip.core.enums import NameType + class TestNameValue(TestCase): @@ -55,21 +58,57 @@ class TestName(TestCase): def setUp(self): super(TestName, self).setUp() self.stream = BytearrayStream() + self.badFormatName = 8675309 + self.stringName1 = 'Jenny' + self.enumNameType = NameType.UNINTERPRETED_TEXT_STRING def tearDown(self): super(TestName, self).tearDown() - def test_minimum_write(self): - self.skip('Not implemented') + def test_bad_name_value_format(self): + """ + Test that an error is raised in for an incorrectly formatted name + value + """ + name_obj = Name() + name_obj.name_value = self.badFormatName + name_obj.name_type = self.enumNameType - def test_maximum_write(self): - self.skip('Not implemented') + self.assertRaises(TypeError, name_obj.validate) - def test_minimum_read(self): - self.skip('Not implemented') + def test_bad_name_type_format(self): + """ + Test that an error is raised for an incorrectly formatted name type + """ + name_obj = Name() + name_obj.name_value = self.stringName1 + name_obj.name_type = self.badFormatName - def test_maximum_read(self): - self.skip('Not implemented') + self.assertRaises(TypeError, name_obj.validate) + + def test_name_create_string_input(self): + """ + Test the creation of object names with an enum value for the name type + """ + name_obj = Name.create(self.stringName1, self.enumNameType) + self.assertIsInstance(name_obj.name_value, Name.NameValue) + self.assertEqual(self.stringName1, name_obj.name_value.value) + + def test_name_create_bad_input(self): + """ + Test the creation of object names with a bad value input + """ + name_value = self.badFormatName + name_type = self.enumNameType + + self.assertRaises(TypeError, Name.create, *(name_value, name_type)) + + def test_name_create_bad_type_input(self): + """ + Test the creation of object names with a bad value input + """ + self.assertRaises(TypeError, Name.create, *(self.stringName1, + self.badFormatName)) class TestOperationPolicyName(TestCase):