#NEWLINE# @ mock_ec2 #NEWLINE# def test_ami_attribute_error_cases( ) : #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# image = conn . get_image ( image_id ) #NEWLINE# with assert_raises ( EC2ResponseError ) as cm : #NEWLINE# #INDENT# conn . modify_image_attribute ( image . id , attribute = 'launchPermission' , operation = 'add' , groups = 'everyone' ) #NEWLINE# #UNINDENT# cm . exception . code . should . equal ( 'InvalidAMIAttributeItemValue' ) #NEWLINE# cm . exception . status . should . equal ( 400 ) #NEWLINE# cm . exception . request_id . should_not . be . none #NEWLINE# with assert_raises ( EC2ResponseError ) as cm : #NEWLINE# #INDENT# conn . modify_image_attribute ( image . id , attribute = 'launchPermission' , operation = 'add' , user_ids = '12345678901A' ) #NEWLINE# #UNINDENT# cm . exception . code . should . equal ( 'InvalidAMIAttributeItemValue' ) #NEWLINE# cm . exception . status . should . equal ( 400 ) #NEWLINE# cm . exception . request_id . should_not . be . none #NEWLINE# with assert_raises ( EC2ResponseError ) as cm : #NEWLINE# #INDENT# conn . modify_image_attribute ( image . id , attribute = 'launchPermission' , operation = 'add' , user_ids = '1234567890123' ) #NEWLINE# #UNINDENT# cm . exception . code . should . equal ( 'InvalidAMIAttributeItemValue' ) #NEWLINE# cm . exception . status . should . equal ( 400 ) #NEWLINE# cm . exception . request_id . should_not . be . none #NEWLINE# with assert_raises ( EC2ResponseError ) as cm : #NEWLINE# #INDENT# conn . modify_image_attribute ( image . id , attribute = 'launchPermission' , operation = 'add' , user_ids = '12345678901' ) #NEWLINE# #UNINDENT# cm . exception . code . should . equal ( 'InvalidAMIAttributeItemValue' ) #NEWLINE# cm . exception . status . should . equal ( 400 ) #NEWLINE# cm . exception . request_id . should_not . be . none #NEWLINE# with assert_raises ( EC2ResponseError ) as cm : #NEWLINE# #INDENT# conn . modify_image_attribute ( image . id , attribute = 'launchPermission' , operation = 'add' , user_ids = [ '123456789011' , 'foo' , '123456789022' ] ) #NEWLINE# #UNINDENT# cm . exception . code . should . equal ( 'InvalidAMIAttributeItemValue' ) #NEWLINE# cm . exception . status . should . equal ( 400 ) #NEWLINE# cm . exception . request_id . should_not . be . none #NEWLINE# attributes = conn . get_image_attribute ( image . id , attribute = 'launchPermission' ) #NEWLINE# attributes . attrs . should . have . length_of ( 0 ) #NEWLINE# with assert_raises ( EC2ResponseError ) as cm : #NEWLINE# #INDENT# conn . modify_image_attribute ( 'ami-abcd1234' , attribute = 'launchPermission' , operation = 'add' , groups = 'all' ) #NEWLINE# #UNINDENT# cm . exception . code . should . equal ( 'InvalidAMIID.NotFound' ) #NEWLINE# cm . exception . status . should . equal ( 400 ) #NEWLINE# image . exception . request_id . should_not . be . none #NEWLINE# with assert_raises ( EC2ResponseError ) as cm : #NEWLINE# #INDENT# conn . modify_image_attribute ( 'ami-abcd1234' , attribute = 'launchPermission' , operation = 'remove' , groups = 'all' ) #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