<s> import testtools <EOL> from ec2api . tests . functional import base <EOL> from ec2api . tests . functional import config <EOL> CONF = config . CONF <EOL> class KeyPairTest ( base . EC2TestCase ) : <EOL> def test_create_delete_key_pair ( self ) : <EOL> keyName = '<STR_LIT>' <EOL> data = self . client . create_key_pair ( KeyName = keyName ) <EOL> res_clean = self . addResourceCleanUp ( self . client . delete_key_pair , <EOL> KeyName = keyName ) <EOL> self . assertEqual ( keyName , data [ '<STR_LIT>' ] ) <EOL> self . assertIsNotNone ( data . get ( '<STR_LIT>' ) ) <EOL> self . assertGreater ( len ( data [ '<STR_LIT>' ] ) , <NUM_LIT:0> ) <EOL> self . assertGreater ( len ( data . get ( '<STR_LIT>' ) ) , <NUM_LIT:0> ) <EOL> data = self . client . delete_key_pair ( KeyName = keyName ) <EOL> self . cancelResourceCleanUp ( res_clean ) <EOL> def test_create_duplicate_key_pair ( self ) : <EOL> keyName = '<STR_LIT>' <EOL> self . client . create_key_pair ( KeyName = keyName ) <EOL> res_clean = self . addResourceCleanUp ( self . client . delete_key_pair , <EOL> KeyName = keyName ) <EOL> self . assertRaises ( '<STR_LIT>' , <EOL> self . client . create_key_pair , <EOL> KeyName = keyName ) <EOL> self . client . delete_key_pair ( KeyName = keyName ) <EOL> self . cancelResourceCleanUp ( res_clean ) <EOL> def test_describe_key_pairs ( self ) : <EOL> keyName = '<STR_LIT>' <EOL> data = self . client . create_key_pair ( KeyName = keyName ) <EOL> res_clean = self . addResourceCleanUp ( self . client . delete_key_pair , <EOL> KeyName = keyName ) <EOL> self . assertIsNotNone ( data . get ( '<STR_LIT>' ) ) <EOL> self . assertGreater ( len ( data [ '<STR_LIT>' ] ) , <NUM_LIT:0> ) <EOL> fingerprint = data . get ( '<STR_LIT>' ) <EOL> data = self . client . describe_key_pairs ( KeyNames = [ keyName ] ) <EOL> self . assertEqual ( <NUM_LIT:1> , len ( data . get ( '<STR_LIT>' ) ) ) <EOL> data = data [ '<STR_LIT>' ] [ <NUM_LIT:0> ] <EOL> self . assertEqual ( keyName , data [ '<STR_LIT>' ] ) <EOL> self . assertIsNotNone ( data . get ( '<STR_LIT>' ) ) <EOL> self . assertGreater ( len ( data [ '<STR_LIT>' ] ) , <NUM_LIT:0> ) <EOL> self . assertIsNone ( data . get ( '<STR_LIT>' ) ) <EOL> data = self . client . describe_key_pairs ( <EOL> Filters = [ { '<STR_LIT:Name>' : '<STR_LIT>' , '<STR_LIT>' : [ keyName ] } ] ) <EOL> self . assertEqual ( <NUM_LIT:1> , len ( data . get ( '<STR_LIT>' ) ) ) <EOL> self . assertEqual ( keyName , data [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ '<STR_LIT>' ] ) <EOL> data = self . client . describe_key_pairs ( <EOL> Filters = [ { '<STR_LIT:Name>' : '<STR_LIT>' , '<STR_LIT>' : [ fingerprint ] } ] ) <EOL> self . assertEqual ( <NUM_LIT:1> , len ( data . get ( '<STR_LIT>' ) ) ) <EOL> self . assertEqual ( keyName , data [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ '<STR_LIT>' ] ) <EOL> self . assertRaises ( '<STR_LIT>' , <EOL> self . client . describe_key_pairs , <EOL> KeyNames = [ '<STR_LIT>' ] ) <EOL> data = self . client . delete_key_pair ( KeyName = keyName ) <EOL> self . cancelResourceCleanUp ( res_clean ) <EOL> self . assertRaises ( '<STR_LIT>' , <EOL> self . client . describe_key_pairs , <EOL> KeyNames = [ keyName ] ) <EOL> self . client . delete_key_pair ( KeyName = keyName ) <EOL> def test_import_empty_key_pair ( self ) : <EOL> keyName = '<STR_LIT>' <EOL> publicKey = '<STR_LIT>' <EOL> def _rollback ( fn_data ) : <EOL> self . client . delete_key_pair ( KeyName = keyName ) <EOL> self . assertRaises ( '<STR_LIT>' , <EOL> self . client . import_key_pair , <EOL> rollback_fn = _rollback , <EOL> KeyName = keyName , PublicKeyMaterial = publicKey ) <EOL> @ testtools . skipUnless ( CONF . aws . run_incompatible_tests , <EOL> "<STR_LIT>" ) <EOL> def test_import_invalid_key_pair ( self ) : <EOL> keyName = '<STR_LIT>' <EOL> publicKey = '<STR_LIT>' <EOL> def _rollback ( ) : <EOL> self . client . delete_key_pair ( KeyName = keyName ) <EOL> self . assertRaises ( '<STR_LIT>' , <EOL> self . client . import_key_pair , <EOL> rollback_fn = _rollback , <EOL> KeyName = keyName , PublicKeyMaterial = publicKey ) <EOL> def test_import_key_pair ( self ) : <EOL> keyName = '<STR_LIT>' <EOL> publicKey = ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> data = self . client . import_key_pair ( KeyName = keyName , <EOL> PublicKeyMaterial = publicKey ) <EOL> res_clean = self . addResourceCleanUp ( self . client . delete_key_pair , <EOL> KeyName = keyName ) <EOL> self . assertEqual ( keyName , data [ '<STR_LIT>' ] ) <EOL> self . assertIsNotNone ( data . get ( '<STR_LIT>' ) ) <EOL> self . assertGreater ( len ( data [ '<STR_LIT>' ] ) , <NUM_LIT:0> ) <EOL> self . assertIsNone ( data . get ( '<STR_LIT>' ) ) <EOL> self . client . delete_key_pair ( KeyName = keyName ) <EOL> self . cancelResourceCleanUp ( res_clean ) </s>
