<s> """<STR_LIT>""" <EOL> from cafe . drivers . unittest . decorators import tags <EOL> from cloudcafe . common . tools . datagen import rand_name <EOL> from cloudcafe . compute . common . exceptions import ActionInProgress <EOL> from cloudcafe . compute . common . types import InstanceAuthStrategies <EOL> from cloudroast . compute . fixtures import ComputeFixture <EOL> class CreateKeypairTest ( ComputeFixture ) : <EOL> @ classmethod <EOL> def setUpClass ( cls ) : <EOL> """<STR_LIT>""" <EOL> super ( CreateKeypairTest , cls ) . setUpClass ( ) <EOL> cls . name = rand_name ( "<STR_LIT:key>" ) <EOL> cls . create_resp = cls . keypairs_client . create_keypair ( cls . name ) <EOL> cls . keypair = cls . keypairs_client . get_keypair ( cls . name ) . entity <EOL> cls . resources . add ( cls . name , <EOL> cls . keypairs_client . delete_keypair ) <EOL> @ tags ( type = '<STR_LIT>' , net = '<STR_LIT>' ) <EOL> def test_create_keypair_response ( self ) : <EOL> """<STR_LIT>""" <EOL> keypair = self . create_resp . entity <EOL> self . assertEqual ( self . create_resp . status_code , <NUM_LIT:200> ) <EOL> self . assertEqual ( keypair . name , self . name ) <EOL> self . assertIsNotNone ( keypair . public_key ) <EOL> self . assertIsNotNone ( keypair . fingerprint ) <EOL> @ tags ( type = '<STR_LIT>' , net = '<STR_LIT>' ) <EOL> def test_created_keypair_listed ( self ) : <EOL> """<STR_LIT>""" <EOL> keypairs_list = self . keypairs_client . list_keypairs ( ) . entity <EOL> self . assertTrue ( any ( [ key for key in keypairs_list <EOL> if key . name == self . keypair . name ] ) ) <EOL> @ tags ( type = '<STR_LIT>' , net = '<STR_LIT>' ) <EOL> def test_cannot_create_duplicate_keypair ( self ) : <EOL> """<STR_LIT>""" <EOL> with self . assertRaises ( ActionInProgress ) : <EOL> self . keypairs_client . create_keypair ( self . name ) <EOL> @ tags ( type = '<STR_LIT>' , net = '<STR_LIT:yes>' ) <EOL> def test_created_server_has_new_keypair ( self ) : <EOL> """<STR_LIT>""" <EOL> server = self . server_behaviors . create_active_server ( <EOL> key_name = self . name ) . entity <EOL> self . resources . add ( server . id , self . servers_client . delete_server ) <EOL> keypair = self . create_resp . entity <EOL> remote_client = self . server_behaviors . get_remote_instance_client ( <EOL> server , self . servers_config , key = keypair . private_key , <EOL> auth_strategy = InstanceAuthStrategies . KEY ) <EOL> self . assertTrue ( remote_client . is_file_present ( <EOL> '<STR_LIT>' ) ) <EOL> file_contents = remote_client . get_file_details ( <EOL> '<STR_LIT>' ) <EOL> self . assertIn ( self . keypair . public_key , file_contents . content ) </s>
