def test_get_attributes(self): """ Test that a secret's attributes can be retrieved with proper input. """ result = results.GetAttributesResult( contents.ResultStatus(enums.ResultStatus.SUCCESS), uuid='aaaaaaaa-1111-2222-3333-ffffffffffff', attributes=[ obj.Attribute( attribute_name=obj.Attribute.AttributeName('Name'), attribute_index=obj.Attribute.AttributeIndex(0), attribute_value=attr.Name( name_value=attr.Name.NameValue('Test Name'), name_type=attr.Name.NameType( enums.NameType.UNINTERPRETED_TEXT_STRING))), obj.Attribute( attribute_name=obj.Attribute.AttributeName('Object Type'), attribute_value=attr.ObjectType( enums.ObjectType.SYMMETRIC_KEY)) ]) with ProxyKmipClient() as client: client.proxy.get_attributes.return_value = result result = client.get_attributes( 'aaaaaaaa-1111-2222-3333-ffffffffffff', ['Name', 'Object Type']) client.proxy.get_attributes.assert_called_with( 'aaaaaaaa-1111-2222-3333-ffffffffffff', ['Name', 'Object Type']) self.assertIsInstance(result[0], six.string_types) self.assertIsInstance(result[1], list) for r in result[1]: self.assertIsInstance(r, obj.Attribute)
def _create_name(self, name): if name is not None: name_value = name.name_value name_type = name.name_type return attributes.Name.create(name_value, name_type) else: return attributes.Name()
def _create_name(self, name): if name is not None: if isinstance(name, attributes.Name): return attributes.Name.create(name.name_value, name.name_type) elif isinstance(name, str): return attributes.Name.create( name, enums.NameType.UNINTERPRETED_TEXT_STRING) else: raise ValueError('Unrecognized attribute type: ' '{0}'.format(name)) else: return attributes.Name()
def read(self, istream): super(TemplateAttribute, self).read(istream) tstream = BytearrayStream(istream.read(self.length)) self.names = list() self.attributes = list() # Read the names of the template attribute, 0 or more while self.is_tag_next(Tags.NAME, tstream): name = attributes.Name() name.read(tstream) self.names.append(name) # Read the attributes of the template attribute, 0 or more while self.is_tag_next(Tags.ATTRIBUTE, tstream): attribute = Attribute() attribute.read(tstream) self.attributes.append(attribute) self.is_oversized(tstream) self.validate()