<s> import base64 <EOL> from novaclient import exceptions as nova_exception <EOL> from ec2api . tests . unit import base <EOL> from ec2api . tests . unit import fakes <EOL> from ec2api . tests . unit import matchers <EOL> from ec2api . tests . unit import tools <EOL> class KeyPairCase ( base . ApiTestCase ) : <EOL> def test_create_key_pair ( self ) : <EOL> self . nova . keypairs . create . return_value = ( <EOL> fakes . NovaKeyPair ( fakes . OS_KEY_PAIR ) ) <EOL> resp = self . execute ( '<STR_LIT>' , { '<STR_LIT>' : fakes . NAME_KEY_PAIR } ) <EOL> self . assertThat ( fakes . EC2_KEY_PAIR , matchers . DictMatches ( resp ) ) <EOL> self . nova . keypairs . create . assert_called_once_with ( fakes . NAME_KEY_PAIR ) <EOL> def test_create_key_pair_invalid ( self ) : <EOL> self . nova . keypairs . create . side_effect = ( <EOL> nova_exception . Conflict ( <NUM_LIT> ) ) <EOL> self . assert_execution_error ( <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> { '<STR_LIT>' : fakes . NAME_KEY_PAIR } ) <EOL> self . assert_execution_error ( <EOL> '<STR_LIT>' , '<STR_LIT>' , { '<STR_LIT>' : '<STR_LIT:k>' * <NUM_LIT> } ) <EOL> self . nova . keypairs . create . side_effect = ( <EOL> nova_exception . OverLimit ( <NUM_LIT> ) ) <EOL> self . assert_execution_error ( <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> { '<STR_LIT>' : fakes . NAME_KEY_PAIR } ) <EOL> def test_import_key_pair ( self ) : <EOL> self . nova . keypairs . create . return_value = ( <EOL> fakes . NovaKeyPair ( fakes . OS_KEY_PAIR ) ) <EOL> resp = self . execute ( '<STR_LIT>' , <EOL> { '<STR_LIT>' : fakes . NAME_KEY_PAIR , <EOL> '<STR_LIT>' : base64 . b64encode ( <EOL> fakes . PUBLIC_KEY_KEY_PAIR . encode ( "<STR_LIT:ascii>" ) <EOL> ) . decode ( "<STR_LIT:ascii>" ) } ) <EOL> self . assertThat ( <EOL> tools . purge_dict ( fakes . EC2_KEY_PAIR , { '<STR_LIT>' } ) , <EOL> matchers . DictMatches ( resp ) ) <EOL> self . nova . keypairs . create . assert_called_once_with ( <EOL> fakes . NAME_KEY_PAIR , fakes . PUBLIC_KEY_KEY_PAIR ) <EOL> def test_import_key_pair_invalid ( self ) : <EOL> self . nova . keypairs . create . side_effect = ( <EOL> nova_exception . OverLimit ( <NUM_LIT> ) ) <EOL> self . assert_execution_error ( <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> { '<STR_LIT>' : fakes . NAME_KEY_PAIR , <EOL> '<STR_LIT>' : base64 . b64encode ( <EOL> fakes . PUBLIC_KEY_KEY_PAIR . encode ( "<STR_LIT:ascii>" ) <EOL> ) . decode ( "<STR_LIT:ascii>" ) } ) <EOL> def test_delete_key_pair ( self ) : <EOL> self . nova . keypairs . delete . return_value = True <EOL> self . execute ( '<STR_LIT>' , { '<STR_LIT>' : fakes . NAME_KEY_PAIR } ) <EOL> self . nova . keypairs . delete . assert_called_once_with ( fakes . NAME_KEY_PAIR ) <EOL> self . nova . keypairs . delete . side_effect = nova_exception . NotFound ( <NUM_LIT> ) <EOL> self . execute ( '<STR_LIT>' , { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . nova . keypairs . delete . assert_any_call ( '<STR_LIT>' ) <EOL> def test_describe_key_pairs ( self ) : <EOL> self . nova . keypairs . list . return_value = [ fakes . NovaKeyPair ( <EOL> fakes . OS_KEY_PAIR ) ] <EOL> resp = self . execute ( '<STR_LIT>' , { } ) <EOL> self . assertThat ( resp [ '<STR_LIT>' ] , <EOL> matchers . ListMatches ( [ <EOL> tools . purge_dict ( fakes . EC2_KEY_PAIR , <EOL> { '<STR_LIT>' } ) ] ) ) <EOL> self . nova . keypairs . list . assert_called_once_with ( ) <EOL> self . check_filtering ( <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> [ ( '<STR_LIT>' , fakes . FINGERPRINT_KEY_PAIR ) , <EOL> ( '<STR_LIT>' , fakes . NAME_KEY_PAIR ) ] ) <EOL> def test_describe_key_pairs_invalid ( self ) : <EOL> self . nova . keypairs . list . return_value = [ fakes . NovaKeyPair ( <EOL> fakes . OS_KEY_PAIR ) ] <EOL> self . assert_execution_error ( <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . nova . keypairs . list . assert_called_once_with ( ) </s>
