<s> from testtools import TestCase <EOL> from kmip . core import attributes <EOL> from kmip . core import objects <EOL> from kmip . core import utils <EOL> from kmip . core . messages . payloads import create_key_pair <EOL> class TestCreateKeyPairRequestPayload ( TestCase ) : <EOL> def setUp ( self ) : <EOL> super ( TestCreateKeyPairRequestPayload , self ) . setUp ( ) <EOL> self . common_template_attribute = objects . CommonTemplateAttribute ( ) <EOL> self . private_key_template_attribute = objects . PrivateKeyTemplateAttribute ( ) <EOL> self . public_key_template_attribute = objects . PublicKeyTemplateAttribute ( ) <EOL> self . encoding_empty = utils . BytearrayStream ( ( <EOL> b'<STR_LIT>' ) ) <EOL> self . encoding_full = utils . BytearrayStream ( ( <EOL> b'<STR_LIT>' <EOL> b'<STR_LIT>' <EOL> b'<STR_LIT:\x00>' ) ) <EOL> def tearDown ( self ) : <EOL> super ( TestCreateKeyPairRequestPayload , self ) . tearDown ( ) <EOL> def test_init_with_none ( self ) : <EOL> create_key_pair . CreateKeyPairRequestPayload ( ) <EOL> def test_init_with_args ( self ) : <EOL> create_key_pair . CreateKeyPairRequestPayload ( <EOL> self . common_template_attribute , <EOL> self . private_key_template_attribute , <EOL> self . public_key_template_attribute ) <EOL> def test_validate_with_invalid_common_template_attribute ( self ) : <EOL> kwargs = { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : None } <EOL> self . assertRaisesRegexp ( <EOL> TypeError , "<STR_LIT>" , <EOL> create_key_pair . CreateKeyPairRequestPayload , ** kwargs ) <EOL> def test_validate_with_invalid_private_key_template_attribute ( self ) : <EOL> kwargs = { '<STR_LIT>' : None , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : None } <EOL> self . assertRaisesRegexp ( <EOL> TypeError , "<STR_LIT>" , <EOL> create_key_pair . CreateKeyPairRequestPayload , ** kwargs ) <EOL> def test_validate_with_invalid_public_key_template_attribute ( self ) : <EOL> kwargs = { '<STR_LIT>' : None , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : '<STR_LIT>' } <EOL> self . assertRaises ( <EOL> TypeError , "<STR_LIT>" , <EOL> create_key_pair . CreateKeyPairRequestPayload , ** kwargs ) <EOL> def _test_read ( self , stream , payload , common_template_attribute , <EOL> private_key_template_attribute , <EOL> public_key_template_attribute ) : <EOL> payload . read ( stream ) <EOL> msg = "<STR_LIT>" <EOL> msg += "<STR_LIT>" . format ( <EOL> common_template_attribute , payload . common_template_attribute ) <EOL> self . assertEqual ( common_template_attribute , <EOL> payload . common_template_attribute , msg ) <EOL> msg = "<STR_LIT>" <EOL> msg += "<STR_LIT>" . format ( <EOL> private_key_template_attribute , <EOL> payload . private_key_template_attribute ) <EOL> self . assertEqual ( private_key_template_attribute , <EOL> payload . private_key_template_attribute , msg ) <EOL> msg = "<STR_LIT>" <EOL> msg += "<STR_LIT>" . format ( <EOL> public_key_template_attribute , <EOL> payload . public_key_template_attribute ) <EOL> self . assertEqual ( public_key_template_attribute , <EOL> payload . public_key_template_attribute , msg ) <EOL> def test_read_with_none ( self ) : <EOL> stream = self . encoding_empty <EOL> payload = create_key_pair . CreateKeyPairRequestPayload ( ) <EOL> self . _test_read ( stream , payload , None , None , None ) <EOL> def test_read_with_args ( self ) : <EOL> stream = self . encoding_full <EOL> payload = create_key_pair . CreateKeyPairRequestPayload ( ) <EOL> self . _test_read ( stream , payload , self . common_template_attribute , <EOL> self . private_key_template_attribute , <EOL> self . public_key_template_attribute ) <EOL> def _test_write ( self , stream , payload , expected ) : <EOL> payload . write ( stream ) <EOL> length_expected = len ( expected ) <EOL> length_received = len ( stream ) <EOL> msg = "<STR_LIT>" <EOL> msg += "<STR_LIT>" . format ( <EOL> length_expected , length_received ) <EOL> self . assertEqual ( length_expected , length_received , msg ) <EOL> msg = "<STR_LIT>" <EOL> msg += "<STR_LIT>" . format ( expected , stream ) <EOL> self . assertEqual ( expected , stream , msg ) <EOL> def test_write_with_none ( self ) : <EOL> stream = utils . BytearrayStream ( ) <EOL> payload = create_key_pair . CreateKeyPairRequestPayload ( ) <EOL> self . _test_write ( stream , payload , self . encoding_empty ) <EOL> def test_write_with_args ( self ) : <EOL> stream = utils . BytearrayStream ( ) <EOL> payload = create_key_pair . CreateKeyPairRequestPayload ( <EOL> self . common_template_attribute , <EOL> self . private_key_template_attribute , <EOL> self . public_key_template_attribute ) <EOL> self . _test_write ( stream , payload , self . encoding_full ) <EOL> class TestCreateKeyPairResponsePayload ( TestCase ) : <EOL> def setUp ( self ) : <EOL> super ( TestCreateKeyPairResponsePayload , self ) . setUp ( ) <EOL> self . uuid = '<STR_LIT>' <EOL> self . private_key_uuid = attributes . PrivateKeyUniqueIdentifier ( <EOL> self . uuid ) <EOL> self . public_key_uuid = attributes . PublicKeyUniqueIdentifier ( <EOL> self . uuid ) <EOL> self . empty_private_key_uuid = attributes . PrivateKeyUniqueIdentifier ( '<STR_LIT>' ) <EOL> self . empty_public_key_uuid = attributes . PublicKeyUniqueIdentifier ( '<STR_LIT>' ) <EOL> self . private_key_template_attribute = objects . PrivateKeyTemplateAttribute ( ) <EOL> self . public_key_template_attribute = objects . PublicKeyTemplateAttribute ( ) <EOL> self . encoding_empty = utils . BytearrayStream ( ( <EOL> b'<STR_LIT>' <EOL> b'<STR_LIT>' ) ) <EOL> self . encoding_full = utils . BytearrayStream ( ( <EOL> b'<STR_LIT>' <EOL> b'<STR_LIT>' <EOL> b'<STR_LIT>' <EOL> b'<STR_LIT>' <EOL> b'<STR_LIT>' <EOL> b'<STR_LIT>' <EOL> b'<STR_LIT>' <EOL> b'<STR_LIT>' ) ) <EOL> def tearDown ( self ) : <EOL> super ( TestCreateKeyPairResponsePayload , self ) . tearDown ( ) <EOL> def test_init_with_none ( self ) : <EOL> create_key_pair . CreateKeyPairResponsePayload ( ) <EOL> def test_init_with_args ( self ) : <EOL> create_key_pair . CreateKeyPairResponsePayload ( <EOL> self . private_key_uuid , self . public_key_uuid , <EOL> self . private_key_template_attribute , <EOL> self . public_key_template_attribute ) <EOL> def test_validate_with_invalid_private_key_unique_identifier ( self ) : <EOL> kwargs = { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : None } <EOL> self . assertRaisesRegexp ( <EOL> TypeError , "<STR_LIT>" , <EOL> create_key_pair . CreateKeyPairResponsePayload , ** kwargs ) <EOL> def test_validate_with_invalid_public_key_unique_identifier ( self ) : <EOL> kwargs = { '<STR_LIT>' : None , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : None } <EOL> self . assertRaisesRegexp ( <EOL> TypeError , "<STR_LIT>" , <EOL> create_key_pair . CreateKeyPairResponsePayload , ** kwargs ) <EOL> def test_validate_with_invalid_private_key_template_attribute ( self ) : <EOL> kwargs = { '<STR_LIT>' : self . private_key_uuid , <EOL> '<STR_LIT>' : self . public_key_uuid , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : None } <EOL> self . assertRaisesRegexp ( <EOL> TypeError , "<STR_LIT>" , <EOL> create_key_pair . CreateKeyPairResponsePayload , ** kwargs ) <EOL> def test_validate_with_invalid_public_key_template_attribute ( self ) : <EOL> kwargs = { '<STR_LIT>' : self . private_key_uuid , <EOL> '<STR_LIT>' : self . public_key_uuid , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : '<STR_LIT>' } <EOL> self . assertRaisesRegexp ( <EOL> TypeError , "<STR_LIT>" , <EOL> create_key_pair . CreateKeyPairResponsePayload , ** kwargs ) <EOL> def _test_read ( self , stream , payload , private_key_uuid , public_key_uuid , <EOL> private_key_template_attribute , <EOL> public_key_template_attribute ) : <EOL> payload . read ( stream ) <EOL> msg = "<STR_LIT>" <EOL> msg += "<STR_LIT>" . format ( <EOL> private_key_uuid , payload . private_key_uuid ) <EOL> self . assertEqual ( private_key_uuid , payload . private_key_uuid , msg ) <EOL> msg = "<STR_LIT>" <EOL> msg += "<STR_LIT>" . format ( <EOL> public_key_uuid , payload . public_key_uuid ) <EOL> self . assertEqual ( public_key_uuid , payload . public_key_uuid , msg ) <EOL> msg = "<STR_LIT>" <EOL> msg += "<STR_LIT>" . format ( <EOL> private_key_template_attribute , <EOL> payload . private_key_template_attribute ) <EOL> self . assertEqual ( private_key_template_attribute , <EOL> payload . private_key_template_attribute , msg ) <EOL> msg = "<STR_LIT>" <EOL> msg += "<STR_LIT>" . format ( <EOL> public_key_template_attribute , <EOL> payload . public_key_template_attribute ) <EOL> self . assertEqual ( public_key_template_attribute , <EOL> payload . public_key_template_attribute , msg ) <EOL> def test_read_with_none ( self ) : <EOL> stream = self . encoding_empty <EOL> payload = create_key_pair . CreateKeyPairResponsePayload ( ) <EOL> self . _test_read ( stream , payload , self . empty_private_key_uuid , <EOL> self . empty_public_key_uuid , None , None ) <EOL> def test_read_with_args ( self ) : <EOL> stream = self . encoding_full <EOL> payload = create_key_pair . CreateKeyPairResponsePayload ( <EOL> self . private_key_uuid , self . public_key_uuid , <EOL> self . private_key_template_attribute , <EOL> self . public_key_template_attribute ) <EOL> self . _test_read ( stream , payload , self . private_key_uuid , <EOL> self . public_key_uuid , <EOL> self . private_key_template_attribute , <EOL> self . public_key_template_attribute ) <EOL> def _test_write ( self , stream , payload , expected ) : <EOL> payload . write ( stream ) <EOL> length_expected = len ( expected ) <EOL> length_received = len ( stream ) <EOL> msg = "<STR_LIT>" <EOL> msg += "<STR_LIT>" . format ( <EOL> length_expected , length_received ) <EOL> self . assertEqual ( length_expected , length_received , msg ) <EOL> msg = "<STR_LIT>" <EOL> msg += "<STR_LIT>" . format ( expected , stream ) <EOL> self . assertEqual ( expected , stream , msg ) <EOL> def test_write_with_none ( self ) : <EOL> stream = utils . BytearrayStream ( ) <EOL> payload = create_key_pair . CreateKeyPairResponsePayload ( ) <EOL> self . _test_write ( stream , payload , self . encoding_empty ) <EOL> def test_write_with_args ( self ) : <EOL> stream = utils . BytearrayStream ( ) <EOL> payload = create_key_pair . CreateKeyPairResponsePayload ( <EOL> self . private_key_uuid , self . public_key_uuid , <EOL> self . private_key_template_attribute , <EOL> self . public_key_template_attribute ) <EOL> self . _test_write ( stream , payload , self . encoding_full ) </s>
