#NEWLINE# @ mock_ec2 #NEWLINE# def test_ami_create_and_delete( ) : #NEWLINE# #INDENT# conn = boto . connect_ec2 ( 'the_key' , 'the_secret' ) #NEWLINE# reservation = conn . run_instances ( 'ami-1234abcd' ) #NEWLINE# instance = reservation . instances [ 0 ] #NEWLINE# image_id = conn . create_image ( instance . id , 'test-ami' , 'this is a test ami' ) #NEWLINE# all_images = conn . get_all_images ( ) #NEWLINE# image = all_images [ 0 ] #NEWLINE# image . id . should . equal ( image_id ) #NEWLINE# image . virtualization_type . should . equal ( instance . virtualization_type ) #NEWLINE# image . architecture . should . equal ( instance . architecture ) #NEWLINE# image . kernel_id . should . equal ( instance . kernel ) #NEWLINE# image . platform . should . equal ( instance . platform ) #NEWLINE# instance . terminate ( ) #NEWLINE# volumes = conn . get_all_volumes ( ) #NEWLINE# volumes . should . have . length_of ( 1 ) #NEWLINE# volume = volumes [ 0 ] #NEWLINE# snapshots = conn . get_all_snapshots ( ) #NEWLINE# snapshots . should . have . length_of ( 1 ) #NEWLINE# snapshot = snapshots [ 0 ] #NEWLINE# image . block_device_mapping . current_value . snapshot_id . should . equal ( snapshot . id ) #NEWLINE# snapshot . description . should . equal ( 'Auto-created snapshot for AMI {0}' . format ( image . id ) ) #NEWLINE# snapshot . volume_id . should . equal ( volume . id ) #NEWLINE# success = conn . deregister_image ( image_id ) #NEWLINE# success . should . be . true #NEWLINE# with assert_raises ( EC2ResponseError ) as cm : #NEWLINE# #INDENT# conn . deregister_image ( image_id ) #NEWLINE# #UNINDENT# cm . exception . code . should . equal ( 'InvalidAMIID.NotFound' ) #NEWLINE# cm . exception . status . should . equal ( 400 ) #NEWLINE# cm . exception . request_id . should_not . be . none