#NEWLINE# @ mock_ec2 #NEWLINE# def test_ami_attribute_user_permissions( ) : #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# attributes = conn . get_image_attribute ( image . id , attribute = 'launchPermission' ) #NEWLINE# attributes . name . should . equal ( 'launch_permission' ) #NEWLINE# attributes . attrs . should . have . length_of ( 0 ) #NEWLINE# USER1 = '123456789011' #NEWLINE# USER2 = 123456789022 #NEWLINE# ADD_USERS_ARGS = { #NEWLINE# #INDENT# 'image_id' : image . id , #NEWLINE# 'attribute' : 'launchPermission' , #NEWLINE# 'operation' : 'add' , #NEWLINE# 'user_ids' : [ USER1 , USER2 ] , #NEWLINE# #UNINDENT# } #NEWLINE# REMOVE_USERS_ARGS = { #NEWLINE# #INDENT# 'image_id' : image . id , #NEWLINE# 'attribute' : 'launchPermission' , #NEWLINE# 'operation' : 'remove' , #NEWLINE# 'user_ids' : [ USER1 , USER2 ] , #NEWLINE# #UNINDENT# } #NEWLINE# REMOVE_SINGLE_USER_ARGS = { #NEWLINE# #INDENT# 'image_id' : image . id , #NEWLINE# 'attribute' : 'launchPermission' , #NEWLINE# 'operation' : 'remove' , #NEWLINE# 'user_ids' : [ USER1 ] , #NEWLINE# #UNINDENT# } #NEWLINE# conn . modify_image_attribute ( ** ADD_USERS_ARGS ) #NEWLINE# attributes = conn . get_image_attribute ( image . id , attribute = 'launchPermission' ) #NEWLINE# attributes . attrs [ 'user_ids' ] . should . have . length_of ( 2 ) #NEWLINE# set ( attributes . attrs [ 'user_ids' ] ) . should . equal ( set ( [ str ( USER1 ) , str ( USER2 ) ] ) ) #NEWLINE# image = conn . get_image ( image_id ) #NEWLINE# image . is_public . should . equal ( False ) #NEWLINE# conn . modify_image_attribute . when . called_with ( ** ADD_USERS_ARGS ) . should_not . throw ( EC2ResponseError ) #NEWLINE# conn . modify_image_attribute ( ** REMOVE_SINGLE_USER_ARGS ) #NEWLINE# attributes = conn . get_image_attribute ( image . id , attribute = 'launchPermission' ) #NEWLINE# attributes . attrs [ 'user_ids' ] . should . have . length_of ( 1 ) #NEWLINE# set ( attributes . attrs [ 'user_ids' ] ) . should . equal ( set ( [ str ( USER2 ) ] ) ) #NEWLINE# image = conn . get_image ( image_id ) #NEWLINE# image . is_public . should . equal ( False ) #NEWLINE# conn . modify_image_attribute ( ** REMOVE_USERS_ARGS ) #NEWLINE# attributes = conn . get_image_attribute ( image . id , attribute = 'launchPermission' ) #NEWLINE# attributes . attrs . should . have . length_of ( 0 ) #NEWLINE# image = conn . get_image ( image_id ) #NEWLINE# image . is_public . should . equal ( False ) #NEWLINE# conn . modify_image_attribute . when . called_with ( ** REMOVE_USERS_ARGS ) . should_not . throw ( EC2ResponseError )