<s> import random <EOL> import unittest <EOL> from mock import patch <EOL> from mock import MagicMock as Mock <EOL> import pyrax <EOL> import pyrax . autoscale <EOL> from pyrax . autoscale import AutoScaleClient <EOL> from pyrax . autoscale import AutoScalePolicy <EOL> from pyrax . autoscale import AutoScaleWebhook <EOL> from pyrax . autoscale import ScalingGroup <EOL> from pyrax . autoscale import ScalingGroupManager <EOL> import pyrax . exceptions as exc <EOL> import pyrax . utils as utils <EOL> from pyrax import fakes <EOL> class AutoscaleTest ( unittest . TestCase ) : <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> super ( AutoscaleTest , self ) . __init__ ( * args , ** kwargs ) <EOL> def setUp ( self ) : <EOL> self . identity = fakes . FakeIdentity ( ) <EOL> self . scaling_group = fakes . FakeScalingGroup ( self . identity ) <EOL> def tearDown ( self ) : <EOL> pass <EOL> def test_make_policies ( self ) : <EOL> sg = self . scaling_group <EOL> p1 = utils . random_unicode ( ) <EOL> p2 = utils . random_unicode ( ) <EOL> sg . scalingPolicies = [ { "<STR_LIT:name>" : p1 } , { "<STR_LIT:name>" : p2 } ] <EOL> sg . _make_policies ( ) <EOL> self . assertEqual ( len ( sg . policies ) , <NUM_LIT:2> ) <EOL> polnames = [ pol . name for pol in sg . policies ] <EOL> self . assert_ ( p1 in polnames ) <EOL> self . assert_ ( p2 in polnames ) <EOL> def test_get_state ( self ) : <EOL> sg = self . scaling_group <EOL> mgr = sg . manager <EOL> mgr . get_state = Mock ( ) <EOL> sg . get_state ( ) <EOL> mgr . get_state . assert_called_once_with ( sg ) <EOL> def test_pause ( self ) : <EOL> sg = self . scaling_group <EOL> mgr = sg . manager <EOL> mgr . pause = Mock ( ) <EOL> sg . pause ( ) <EOL> mgr . pause . assert_called_once_with ( sg ) <EOL> def test_resume ( self ) : <EOL> sg = self . scaling_group <EOL> mgr = sg . manager <EOL> mgr . resume = Mock ( ) <EOL> sg . resume ( ) <EOL> mgr . resume . assert_called_once_with ( sg ) <EOL> def test_update ( self ) : <EOL> sg = self . scaling_group <EOL> mgr = sg . manager <EOL> mgr . update = Mock ( ) <EOL> name = utils . random_unicode ( ) <EOL> cooldown = utils . random_unicode ( ) <EOL> min_entities = utils . random_unicode ( ) <EOL> max_entities = utils . random_unicode ( ) <EOL> metadata = utils . random_unicode ( ) <EOL> sg . update ( name = name , cooldown = cooldown , min_entities = min_entities , <EOL> max_entities = max_entities , metadata = metadata ) <EOL> mgr . update . assert_called_once_with ( sg , name = name , cooldown = cooldown , <EOL> min_entities = min_entities , max_entities = max_entities , <EOL> metadata = metadata ) <EOL> def test_update_metadata ( self ) : <EOL> sg = self . scaling_group <EOL> mgr = sg . manager <EOL> mgr . update_metadata = Mock ( ) <EOL> metadata = utils . random_unicode ( ) <EOL> sg . update_metadata ( metadata ) <EOL> mgr . update_metadata . assert_called_once_with ( sg , metadata = metadata ) <EOL> def test_get_configuration ( self ) : <EOL> sg = self . scaling_group <EOL> mgr = sg . manager <EOL> mgr . get_configuration = Mock ( ) <EOL> sg . get_configuration ( ) <EOL> mgr . get_configuration . assert_called_once_with ( sg ) <EOL> def test_get_launch_config ( self ) : <EOL> sg = self . scaling_group <EOL> mgr = sg . manager <EOL> mgr . get_launch_config = Mock ( ) <EOL> sg . get_launch_config ( ) <EOL> mgr . get_launch_config . assert_called_once_with ( sg ) <EOL> def test_update_launch_config ( self ) : <EOL> sg = self . scaling_group <EOL> mgr = sg . manager <EOL> mgr . update_launch_config = Mock ( ) <EOL> server_name = utils . random_unicode ( ) <EOL> flavor = utils . random_unicode ( ) <EOL> image = utils . random_unicode ( ) <EOL> disk_config = utils . random_unicode ( ) <EOL> metadata = utils . random_unicode ( ) <EOL> personality = utils . random_unicode ( ) <EOL> networks = utils . random_unicode ( ) <EOL> load_balancers = utils . random_unicode ( ) <EOL> key_name = utils . random_unicode ( ) <EOL> config_drive = utils . random_unicode ( ) <EOL> user_data = utils . random_unicode ( ) <EOL> sg . update_launch_config ( server_name = server_name , flavor = flavor , <EOL> image = image , disk_config = disk_config , metadata = metadata , <EOL> personality = personality , networks = networks , <EOL> load_balancers = load_balancers , key_name = key_name , <EOL> config_drive = config_drive , user_data = user_data ) <EOL> mgr . update_launch_config . assert_called_once_with ( sg , <EOL> server_name = server_name , flavor = flavor , image = image , <EOL> disk_config = disk_config , metadata = metadata , <EOL> personality = personality , networks = networks , <EOL> load_balancers = load_balancers , key_name = key_name , <EOL> config_drive = config_drive , user_data = user_data ) <EOL> def test_update_launch_metadata ( self ) : <EOL> sg = self . scaling_group <EOL> mgr = sg . manager <EOL> mgr . update_launch_metadata = Mock ( ) <EOL> metadata = utils . random_unicode ( ) <EOL> sg . update_launch_metadata ( metadata ) <EOL> mgr . update_launch_metadata . assert_called_once_with ( sg , metadata ) <EOL> def test_add_policy ( self ) : <EOL> sg = self . scaling_group <EOL> mgr = sg . manager <EOL> name = utils . random_unicode ( ) <EOL> policy_type = utils . random_unicode ( ) <EOL> cooldown = utils . random_unicode ( ) <EOL> change = utils . random_unicode ( ) <EOL> is_percent = utils . random_unicode ( ) <EOL> desired_capacity = utils . random_unicode ( ) <EOL> args = utils . random_unicode ( ) <EOL> mgr . add_policy = Mock ( ) <EOL> sg . add_policy ( name , policy_type , cooldown , change , <EOL> is_percent = is_percent , desired_capacity = desired_capacity , <EOL> args = args ) <EOL> mgr . add_policy . assert_called_once_with ( sg , name , policy_type , cooldown , <EOL> change = change , is_percent = is_percent , <EOL> desired_capacity = desired_capacity , args = args ) <EOL> def test_list_policies ( self ) : <EOL> sg = self . scaling_group <EOL> mgr = sg . manager <EOL> mgr . list_policies = Mock ( ) <EOL> sg . list_policies ( ) <EOL> mgr . list_policies . assert_called_once_with ( sg ) <EOL> def test_get_policy ( self ) : <EOL> sg = self . scaling_group <EOL> mgr = sg . manager <EOL> pol = utils . random_unicode ( ) <EOL> mgr . get_policy = Mock ( ) <EOL> sg . get_policy ( pol ) <EOL> mgr . get_policy . assert_called_once_with ( sg , pol ) <EOL> def test_update_policy ( self ) : <EOL> sg = self . scaling_group <EOL> mgr = sg . manager <EOL> policy = utils . random_unicode ( ) <EOL> name = utils . random_unicode ( ) <EOL> policy_type = utils . random_unicode ( ) <EOL> cooldown = utils . random_unicode ( ) <EOL> change = utils . random_unicode ( ) <EOL> desired_capacity = utils . random_unicode ( ) <EOL> is_percent = utils . random_unicode ( ) <EOL> args = utils . random_unicode ( ) <EOL> mgr . update_policy = Mock ( ) <EOL> sg . update_policy ( policy , name = name , policy_type = policy_type , <EOL> cooldown = cooldown , change = change , is_percent = is_percent , <EOL> desired_capacity = desired_capacity , args = args ) <EOL> mgr . update_policy . assert_called_once_with ( scaling_group = sg , <EOL> policy = policy , name = name , policy_type = policy_type , <EOL> cooldown = cooldown , change = change , is_percent = is_percent , <EOL> desired_capacity = desired_capacity , args = args ) <EOL> def test_execute_policy ( self ) : <EOL> sg = self . scaling_group <EOL> mgr = sg . manager <EOL> pol = utils . random_unicode ( ) <EOL> mgr . execute_policy = Mock ( ) <EOL> sg . execute_policy ( pol ) <EOL> mgr . execute_policy . assert_called_once_with ( scaling_group = sg , <EOL> policy = pol ) <EOL> def test_delete_policy ( self ) : <EOL> sg = self . scaling_group <EOL> mgr = sg . manager <EOL> pol = utils . random_unicode ( ) <EOL> mgr . delete_policy = Mock ( ) <EOL> sg . delete_policy ( pol ) <EOL> mgr . delete_policy . assert_called_once_with ( scaling_group = sg , <EOL> policy = pol ) <EOL> def test_add_webhook ( self ) : <EOL> sg = self . scaling_group <EOL> mgr = sg . manager <EOL> pol = utils . random_unicode ( ) <EOL> name = utils . random_unicode ( ) <EOL> metadata = utils . random_unicode ( ) <EOL> mgr . add_webhook = Mock ( ) <EOL> sg . add_webhook ( pol , name , metadata = metadata ) <EOL> mgr . add_webhook . assert_called_once_with ( sg , pol , name , <EOL> metadata = metadata ) <EOL> def test_list_webhooks ( self ) : <EOL> sg = self . scaling_group <EOL> mgr = sg . manager <EOL> pol = utils . random_unicode ( ) <EOL> mgr . list_webhooks = Mock ( ) <EOL> sg . list_webhooks ( pol ) <EOL> mgr . list_webhooks . assert_called_once_with ( sg , pol ) <EOL> def test_update_webhook ( self ) : <EOL> sg = self . scaling_group <EOL> mgr = sg . manager <EOL> pol = utils . random_unicode ( ) <EOL> hook = utils . random_unicode ( ) <EOL> name = utils . random_unicode ( ) <EOL> metadata = utils . random_unicode ( ) <EOL> mgr . update_webhook = Mock ( ) <EOL> sg . update_webhook ( pol , hook , name = name , metadata = metadata ) <EOL> mgr . update_webhook . assert_called_once_with ( scaling_group = sg , policy = pol , <EOL> webhook = hook , name = name , metadata = metadata ) <EOL> def test_update_webhook_metadata ( self ) : <EOL> sg = self . scaling_group <EOL> mgr = sg . manager <EOL> pol = utils . random_unicode ( ) <EOL> hook = utils . random_unicode ( ) <EOL> metadata = utils . random_unicode ( ) <EOL> mgr . update_webhook_metadata = Mock ( ) <EOL> sg . update_webhook_metadata ( pol , hook , metadata = metadata ) <EOL> mgr . update_webhook_metadata . assert_called_once_with ( sg , pol , hook , <EOL> metadata ) <EOL> def test_delete_webhook ( self ) : <EOL> sg = self . scaling_group <EOL> mgr = sg . manager <EOL> pol = utils . random_unicode ( ) <EOL> hook = utils . random_unicode ( ) <EOL> mgr . delete_webhook = Mock ( ) <EOL> sg . delete_webhook ( pol , hook ) <EOL> mgr . delete_webhook . assert_called_once_with ( sg , pol , hook ) <EOL> def test_policy_count ( self ) : <EOL> sg = self . scaling_group <EOL> num = random . randint ( <NUM_LIT:1> , <NUM_LIT:100> ) <EOL> sg . policies = [ "<STR_LIT:x>" ] * num <EOL> self . assertEqual ( sg . policy_count , num ) <EOL> def test_name ( self ) : <EOL> sg = self . scaling_group <EOL> name = utils . random_unicode ( ) <EOL> newname = utils . random_unicode ( ) <EOL> sg . groupConfiguration = { "<STR_LIT:name>" : name } <EOL> self . assertEqual ( sg . name , name ) <EOL> sg . name = newname <EOL> self . assertEqual ( sg . name , newname ) <EOL> def test_cooldown ( self ) : <EOL> sg = self . scaling_group <EOL> cooldown = utils . random_unicode ( ) <EOL> newcooldown = utils . random_unicode ( ) <EOL> sg . groupConfiguration = { "<STR_LIT>" : cooldown } <EOL> self . assertEqual ( sg . cooldown , cooldown ) <EOL> sg . cooldown = newcooldown <EOL> self . assertEqual ( sg . cooldown , newcooldown ) <EOL> def test_metadata ( self ) : <EOL> sg = self . scaling_group <EOL> metadata = utils . random_unicode ( ) <EOL> newmetadata = utils . random_unicode ( ) <EOL> sg . groupConfiguration = { "<STR_LIT>" : metadata } <EOL> self . assertEqual ( sg . metadata , metadata ) <EOL> sg . metadata = newmetadata <EOL> self . assertEqual ( sg . metadata , newmetadata ) <EOL> def test_min_entities ( self ) : <EOL> sg = self . scaling_group <EOL> min_entities = utils . random_unicode ( ) <EOL> newmin_entities = utils . random_unicode ( ) <EOL> sg . groupConfiguration = { "<STR_LIT>" : min_entities } <EOL> self . assertEqual ( sg . min_entities , min_entities ) <EOL> sg . min_entities = newmin_entities <EOL> self . assertEqual ( sg . min_entities , newmin_entities ) <EOL> def test_max_entities ( self ) : <EOL> sg = self . scaling_group <EOL> max_entities = utils . random_unicode ( ) <EOL> newmax_entities = utils . random_unicode ( ) <EOL> sg . groupConfiguration = { "<STR_LIT>" : max_entities } <EOL> self . assertEqual ( sg . max_entities , max_entities ) <EOL> sg . max_entities = newmax_entities <EOL> self . assertEqual ( sg . max_entities , newmax_entities ) <EOL> def test_mgr_get_state ( self ) : <EOL> sg = self . scaling_group <EOL> mgr = sg . manager <EOL> id1 = utils . random_unicode ( ) <EOL> id2 = utils . random_unicode ( ) <EOL> ac = utils . random_unicode ( ) <EOL> dc = utils . random_unicode ( ) <EOL> pc = utils . random_unicode ( ) <EOL> paused = utils . random_unicode ( ) <EOL> statedict = { "<STR_LIT>" : { <EOL> "<STR_LIT>" : [ { "<STR_LIT:id>" : id1 } , { "<STR_LIT:id>" : id2 } ] , <EOL> "<STR_LIT>" : ac , <EOL> "<STR_LIT>" : dc , <EOL> "<STR_LIT>" : pc , <EOL> "<STR_LIT>" : paused , <EOL> } } <EOL> expected = { <EOL> "<STR_LIT>" : [ id1 , id2 ] , <EOL> "<STR_LIT>" : ac , <EOL> "<STR_LIT>" : dc , <EOL> "<STR_LIT>" : pc , <EOL> "<STR_LIT>" : paused , <EOL> } <EOL> mgr . api . method_get = Mock ( return_value = ( None , statedict ) ) <EOL> ret = mgr . get_state ( sg ) <EOL> self . assertEqual ( ret , expected ) <EOL> def test_mgr_pause ( self ) : <EOL> sg = self . scaling_group <EOL> mgr = sg . manager <EOL> uri = "<STR_LIT>" % ( mgr . uri_base , sg . id ) <EOL> mgr . api . method_post = Mock ( return_value = ( None , None ) ) <EOL> mgr . pause ( sg ) <EOL> mgr . api . method_post . assert_called_once_with ( uri ) <EOL> def test_mgr_resume ( self ) : <EOL> sg = self . scaling_group <EOL> mgr = sg . manager <EOL> uri = "<STR_LIT>" % ( mgr . uri_base , sg . id ) <EOL> mgr . api . method_post = Mock ( return_value = ( None , None ) ) <EOL> mgr . resume ( sg ) <EOL> mgr . api . method_post . assert_called_once_with ( uri ) <EOL> def test_mgr_get_configuration ( self ) : <EOL> sg = self . scaling_group <EOL> mgr = sg . manager <EOL> uri = "<STR_LIT>" % ( mgr . uri_base , sg . id ) <EOL> conf = utils . random_unicode ( ) <EOL> resp_body = { "<STR_LIT>" : conf } <EOL> mgr . api . method_get = Mock ( return_value = ( None , resp_body ) ) <EOL> ret = mgr . get_configuration ( sg ) <EOL> mgr . api . method_get . assert_called_once_with ( uri ) <EOL> self . assertEqual ( ret , conf ) <EOL> def test_mgr_update ( self ) : <EOL> sg = self . scaling_group <EOL> mgr = sg . manager <EOL> mgr . get = Mock ( return_value = sg ) <EOL> uri = "<STR_LIT>" % ( mgr . uri_base , sg . id ) <EOL> sg . name = utils . random_unicode ( ) <EOL> sg . cooldown = utils . random_unicode ( ) <EOL> sg . min_entities = utils . random_unicode ( ) <EOL> sg . max_entities = utils . random_unicode ( ) <EOL> metadata = utils . random_unicode ( ) <EOL> mgr . api . method_put = Mock ( return_value = ( None , None ) ) <EOL> expected_body = { "<STR_LIT:name>" : sg . name , <EOL> "<STR_LIT>" : sg . cooldown , <EOL> "<STR_LIT>" : sg . min_entities , <EOL> "<STR_LIT>" : sg . max_entities , <EOL> "<STR_LIT>" : metadata , <EOL> } <EOL> mgr . update ( sg . id , metadata = metadata ) <EOL> mgr . api . method_put . assert_called_once_with ( uri , body = expected_body ) <EOL> def test_mgr_replace ( self ) : <EOL> sg = self . scaling_group <EOL> mgr = sg . manager <EOL> mgr . get = Mock ( return_value = sg ) <EOL> uri = "<STR_LIT>" % ( mgr . uri_base , sg . id ) <EOL> sg . name = utils . random_unicode ( ) <EOL> sg . cooldown = utils . random_unicode ( ) <EOL> sg . min_entities = utils . random_unicode ( ) <EOL> sg . max_entities = utils . random_unicode ( ) <EOL> metadata = utils . random_unicode ( ) <EOL> new_name = utils . random_unicode ( ) <EOL> new_cooldown = utils . random_unicode ( ) <EOL> new_min = utils . random_unicode ( ) <EOL> new_max = utils . random_unicode ( ) <EOL> mgr . api . method_put = Mock ( return_value = ( None , None ) ) <EOL> expected_body = { <EOL> "<STR_LIT:name>" : new_name , <EOL> "<STR_LIT>" : new_cooldown , <EOL> "<STR_LIT>" : new_min , <EOL> "<STR_LIT>" : new_max , <EOL> "<STR_LIT>" : { } <EOL> } <EOL> mgr . replace ( sg . id , new_name , new_cooldown , new_min , new_max ) <EOL> mgr . api . method_put . assert_called_once_with ( uri , body = expected_body ) <EOL> def test_mgr_update_metadata ( self ) : <EOL> sg = self . scaling_group <EOL> mgr = sg . manager <EOL> mgr . get = Mock ( return_value = sg ) <EOL> sg . metadata = { "<STR_LIT>" : "<STR_LIT>" } <EOL> metadata = { "<STR_LIT>" : "<STR_LIT>" } <EOL> expected = sg . metadata . copy ( ) <EOL> expected . update ( metadata ) <EOL> mgr . update = Mock ( ) <EOL> mgr . update_metadata ( sg . id , metadata ) <EOL> mgr . update . assert_called_once_with ( sg , metadata = expected ) <EOL> def test_mgr_get_launch_config ( self ) : <EOL> sg = self . scaling_group <EOL> mgr = sg . manager <EOL> typ = utils . random_unicode ( ) <EOL> lbs = utils . random_unicode ( ) <EOL> name = utils . random_unicode ( ) <EOL> flv = utils . random_unicode ( ) <EOL> img = utils . random_unicode ( ) <EOL> dconfig = utils . random_unicode ( ) <EOL> metadata = utils . random_unicode ( ) <EOL> personality = utils . random_unicode ( ) <EOL> networks = utils . random_unicode ( ) <EOL> key_name = utils . random_unicode ( ) <EOL> launchdict = { "<STR_LIT>" : <EOL> { "<STR_LIT:type>" : typ , <EOL> "<STR_LIT:args>" : { <EOL> "<STR_LIT>" : lbs , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:name>" : name , <EOL> "<STR_LIT>" : flv , <EOL> "<STR_LIT>" : img , <EOL> "<STR_LIT>" : dconfig , <EOL> "<STR_LIT>" : metadata , <EOL> "<STR_LIT>" : personality , <EOL> "<STR_LIT>" : networks , <EOL> "<STR_LIT>" : key_name , <EOL> } , <EOL> } , <EOL> } , <EOL> } <EOL> expected = { <EOL> "<STR_LIT:type>" : typ , <EOL> "<STR_LIT>" : lbs , <EOL> "<STR_LIT:name>" : name , <EOL> "<STR_LIT>" : flv , <EOL> "<STR_LIT:image>" : img , <EOL> "<STR_LIT>" : dconfig , <EOL> "<STR_LIT>" : metadata , <EOL> "<STR_LIT>" : personality , <EOL> "<STR_LIT>" : networks , <EOL> "<STR_LIT>" : key_name , <EOL> } <EOL> mgr . api . method_get = Mock ( return_value = ( None , launchdict ) ) <EOL> uri = "<STR_LIT>" % ( mgr . uri_base , sg . id ) <EOL> ret = mgr . get_launch_config ( sg ) <EOL> mgr . api . method_get . assert_called_once_with ( uri ) <EOL> self . assertEqual ( ret , expected ) <EOL> def test_mgr_update_launch_config ( self ) : <EOL> sg = self . scaling_group <EOL> mgr = sg . manager <EOL> mgr . get = Mock ( return_value = sg ) <EOL> typ = utils . random_unicode ( ) <EOL> lbs = utils . random_unicode ( ) <EOL> name = utils . random_unicode ( ) <EOL> flv = utils . random_unicode ( ) <EOL> img = utils . random_unicode ( ) <EOL> dconfig = utils . random_unicode ( ) <EOL> metadata = utils . random_unicode ( ) <EOL> personality = utils . random_unicode ( ) <EOL> networks = utils . random_unicode ( ) <EOL> sg . launchConfiguration = { } <EOL> body = { "<STR_LIT:type>" : "<STR_LIT>" , <EOL> "<STR_LIT:args>" : { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:name>" : name , <EOL> "<STR_LIT>" : img , <EOL> "<STR_LIT>" : flv , <EOL> "<STR_LIT>" : dconfig , <EOL> "<STR_LIT>" : mgr . _encode_personality ( personality ) , <EOL> "<STR_LIT>" : networks , <EOL> "<STR_LIT>" : metadata , <EOL> } , <EOL> "<STR_LIT>" : lbs , <EOL> } , <EOL> } <EOL> mgr . api . method_put = Mock ( return_value = ( None , None ) ) <EOL> uri = "<STR_LIT>" % ( mgr . uri_base , sg . id ) <EOL> mgr . update_launch_config ( sg . id , server_name = name , flavor = flv , image = img , <EOL> disk_config = dconfig , metadata = metadata , <EOL> personality = personality , networks = networks , load_balancers = lbs ) <EOL> mgr . api . method_put . assert_called_once_with ( uri , body = body ) <EOL> def test_mgr_update_launch_config_unset_personality ( self ) : <EOL> sg = self . scaling_group <EOL> mgr = sg . manager <EOL> mgr . get = Mock ( return_value = sg ) <EOL> typ = utils . random_unicode ( ) <EOL> lbs = utils . random_unicode ( ) <EOL> name = utils . random_unicode ( ) <EOL> flv = utils . random_unicode ( ) <EOL> img = utils . random_unicode ( ) <EOL> dconfig = utils . random_unicode ( ) <EOL> metadata = utils . random_unicode ( ) <EOL> personality = [ { <EOL> "<STR_LIT:path>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" <EOL> } ] <EOL> networks = utils . random_unicode ( ) <EOL> sg . launchConfiguration = { <EOL> "<STR_LIT:type>" : "<STR_LIT>" , <EOL> "<STR_LIT:args>" : { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:name>" : name , <EOL> "<STR_LIT>" : img , <EOL> "<STR_LIT>" : flv , <EOL> "<STR_LIT>" : dconfig , <EOL> "<STR_LIT>" : personality , <EOL> "<STR_LIT>" : networks , <EOL> "<STR_LIT>" : metadata , <EOL> } , <EOL> "<STR_LIT>" : lbs , <EOL> } , <EOL> } <EOL> body = { <EOL> "<STR_LIT:type>" : "<STR_LIT>" , <EOL> "<STR_LIT:args>" : { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:name>" : name , <EOL> "<STR_LIT>" : img , <EOL> "<STR_LIT>" : flv , <EOL> "<STR_LIT>" : dconfig , <EOL> "<STR_LIT>" : networks , <EOL> "<STR_LIT>" : metadata , <EOL> } , <EOL> "<STR_LIT>" : lbs , <EOL> } , <EOL> } <EOL> mgr . api . method_put = Mock ( return_value = ( None , None ) ) <EOL> uri = "<STR_LIT>" % ( mgr . uri_base , sg . id ) <EOL> mgr . update_launch_config ( sg . id , server_name = name , flavor = flv , image = img , <EOL> disk_config = dconfig , metadata = metadata , <EOL> personality = [ ] , networks = networks , load_balancers = lbs ) <EOL> mgr . api . method_put . assert_called_once_with ( uri , body = body ) <EOL> def test_mgr_update_launch_config_no_personality ( self ) : <EOL> sg = self . scaling_group <EOL> mgr = sg . manager <EOL> mgr . get = Mock ( return_value = sg ) <EOL> typ = utils . random_unicode ( ) <EOL> lbs = utils . random_unicode ( ) <EOL> name = utils . random_unicode ( ) <EOL> flv = utils . random_unicode ( ) <EOL> img = utils . random_unicode ( ) <EOL> dconfig = utils . random_unicode ( ) <EOL> metadata = utils . random_unicode ( ) <EOL> networks = utils . random_unicode ( ) <EOL> sg . launchConfiguration = { } <EOL> body = { "<STR_LIT:type>" : "<STR_LIT>" , <EOL> "<STR_LIT:args>" : { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:name>" : name , <EOL> "<STR_LIT>" : img , <EOL> "<STR_LIT>" : flv , <EOL> "<STR_LIT>" : dconfig , <EOL> "<STR_LIT>" : networks , <EOL> "<STR_LIT>" : metadata , <EOL> } , <EOL> "<STR_LIT>" : lbs , <EOL> } , <EOL> } <EOL> mgr . api . method_put = Mock ( return_value = ( None , None ) ) <EOL> uri = "<STR_LIT>" % ( mgr . uri_base , sg . id ) <EOL> mgr . update_launch_config ( sg . id , server_name = name , flavor = flv , image = img , <EOL> disk_config = dconfig , metadata = metadata , <EOL> networks = networks , load_balancers = lbs ) <EOL> mgr . api . method_put . assert_called_once_with ( uri , body = body ) <EOL> def test_mgr_update_launch_config_no_metadata ( self ) : <EOL> sg = self . scaling_group <EOL> mgr = sg . manager <EOL> mgr . get = Mock ( return_value = sg ) <EOL> typ = utils . random_unicode ( ) <EOL> lbs = utils . random_unicode ( ) <EOL> name = utils . random_unicode ( ) <EOL> flv = utils . random_unicode ( ) <EOL> img = utils . random_unicode ( ) <EOL> dconfig = utils . random_unicode ( ) <EOL> networks = utils . random_unicode ( ) <EOL> sg . launchConfiguration = { } <EOL> body = { "<STR_LIT:type>" : "<STR_LIT>" , <EOL> "<STR_LIT:args>" : { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:name>" : name , <EOL> "<STR_LIT>" : img , <EOL> "<STR_LIT>" : flv , <EOL> "<STR_LIT>" : dconfig , <EOL> "<STR_LIT>" : networks , <EOL> } , <EOL> "<STR_LIT>" : lbs , <EOL> } , <EOL> } <EOL> mgr . api . method_put = Mock ( return_value = ( None , None ) ) <EOL> uri = "<STR_LIT>" % ( mgr . uri_base , sg . id ) <EOL> mgr . update_launch_config ( sg . id , server_name = name , flavor = flv , image = img , <EOL> disk_config = dconfig , networks = networks , load_balancers = lbs ) <EOL> mgr . api . method_put . assert_called_once_with ( uri , body = body ) <EOL> def test_mgr_update_launch_config_key_name ( self ) : <EOL> sg = self . scaling_group <EOL> mgr = sg . manager <EOL> mgr . get = Mock ( return_value = sg ) <EOL> typ = utils . random_unicode ( ) <EOL> lbs = utils . random_unicode ( ) <EOL> name = utils . random_unicode ( ) <EOL> flv = utils . random_unicode ( ) <EOL> img = utils . random_unicode ( ) <EOL> dconfig = utils . random_unicode ( ) <EOL> metadata = utils . random_unicode ( ) <EOL> personality = utils . random_unicode ( ) <EOL> networks = utils . random_unicode ( ) <EOL> key_name = utils . random_unicode ( ) <EOL> sg . launchConfiguration = { } <EOL> body = { "<STR_LIT:type>" : "<STR_LIT>" , <EOL> "<STR_LIT:args>" : { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:name>" : name , <EOL> "<STR_LIT>" : img , <EOL> "<STR_LIT>" : flv , <EOL> "<STR_LIT>" : dconfig , <EOL> "<STR_LIT>" : networks , <EOL> "<STR_LIT>" : metadata , <EOL> "<STR_LIT>" : key_name , <EOL> "<STR_LIT>" : mgr . _encode_personality ( personality ) , <EOL> } , <EOL> "<STR_LIT>" : lbs , <EOL> } , <EOL> } <EOL> mgr . api . method_put = Mock ( return_value = ( None , None ) ) <EOL> uri = "<STR_LIT>" % ( mgr . uri_base , sg . id ) <EOL> mgr . update_launch_config ( sg . id , server_name = name , flavor = flv , image = img , <EOL> disk_config = dconfig , metadata = metadata , <EOL> personality = personality , networks = networks , load_balancers = lbs , <EOL> key_name = key_name ) <EOL> mgr . api . method_put . assert_called_once_with ( uri , body = body ) <EOL> def test_mgr_replace_launch_config ( self ) : <EOL> sg = self . scaling_group <EOL> mgr = sg . manager <EOL> mgr . get = Mock ( return_value = sg ) <EOL> typ = utils . random_unicode ( ) <EOL> lbs = utils . random_unicode ( ) <EOL> name = utils . random_unicode ( ) <EOL> flv = utils . random_unicode ( ) <EOL> img = utils . random_unicode ( ) <EOL> dconfig = utils . random_unicode ( ) <EOL> metadata = utils . random_unicode ( ) <EOL> personality = utils . random_unicode ( ) <EOL> networks = utils . random_unicode ( ) <EOL> sg . launchConfiguration = { <EOL> "<STR_LIT:type>" : typ , <EOL> "<STR_LIT:args>" : { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:name>" : name , <EOL> "<STR_LIT>" : img , <EOL> "<STR_LIT>" : flv , <EOL> "<STR_LIT>" : dconfig , <EOL> "<STR_LIT>" : personality , <EOL> "<STR_LIT>" : networks , <EOL> "<STR_LIT>" : metadata , <EOL> } , <EOL> "<STR_LIT>" : lbs , <EOL> } , <EOL> } <EOL> new_typ = utils . random_unicode ( ) <EOL> new_name = utils . random_unicode ( ) <EOL> new_flv = utils . random_unicode ( ) <EOL> new_img = utils . random_unicode ( ) <EOL> expected = { <EOL> "<STR_LIT:type>" : new_typ , <EOL> "<STR_LIT:args>" : { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:name>" : new_name , <EOL> "<STR_LIT>" : new_img , <EOL> "<STR_LIT>" : new_flv , <EOL> } , <EOL> "<STR_LIT>" : [ ] <EOL> } <EOL> } <EOL> mgr . api . method_put = Mock ( return_value = ( None , None ) ) <EOL> uri = "<STR_LIT>" % ( mgr . uri_base , sg . id ) <EOL> mgr . replace_launch_config ( sg . id , launch_config_type = new_typ , <EOL> server_name = new_name , flavor = new_flv , image = new_img ) <EOL> mgr . api . method_put . assert_called_once_with ( uri , body = expected ) <EOL> def test_mgr_update_launch_metadata ( self ) : <EOL> sg = self . scaling_group <EOL> mgr = sg . manager <EOL> mgr . get = Mock ( return_value = sg ) <EOL> orig_meta = { "<STR_LIT>" : "<STR_LIT>" } <EOL> new_meta = { "<STR_LIT>" : "<STR_LIT>" } <EOL> sg . launchConfiguration = { "<STR_LIT:args>" : { "<STR_LIT>" : { "<STR_LIT>" : orig_meta } } } <EOL> expected = orig_meta . copy ( ) <EOL> expected . update ( new_meta ) <EOL> mgr . update_launch_config = Mock ( ) <EOL> mgr . update_launch_metadata ( sg . id , new_meta ) <EOL> mgr . update_launch_config . assert_called_once_with ( sg , metadata = expected ) <EOL> def test_mgr_add_policy ( self ) : <EOL> sg = self . scaling_group <EOL> mgr = sg . manager <EOL> ret_body = { "<STR_LIT>" : [ { } ] } <EOL> mgr . api . method_post = Mock ( return_value = ( None , ret_body ) ) <EOL> uri = "<STR_LIT>" % ( mgr . uri_base , sg . id ) <EOL> name = utils . random_unicode ( ) <EOL> ptype = utils . random_unicode ( ) <EOL> cooldown = utils . random_unicode ( ) <EOL> change = utils . random_unicode ( ) <EOL> for is_percent in ( True , False ) : <EOL> post_body = { "<STR_LIT:name>" : name , "<STR_LIT>" : cooldown , "<STR_LIT:type>" : ptype } <EOL> if is_percent : <EOL> post_body [ "<STR_LIT>" ] = change <EOL> else : <EOL> post_body [ "<STR_LIT>" ] = change <EOL> ret = mgr . add_policy ( sg , name , ptype , cooldown , change , <EOL> is_percent = is_percent ) <EOL> mgr . api . method_post . assert_called_with ( uri , body = [ post_body ] ) <EOL> self . assert_ ( isinstance ( ret , AutoScalePolicy ) ) <EOL> def test_mgr_create_policy_body ( self ) : <EOL> sg = self . scaling_group <EOL> mgr = sg . manager <EOL> name = utils . random_unicode ( ) <EOL> ptype = utils . random_unicode ( ) <EOL> cooldown = utils . random_unicode ( ) <EOL> desired_capacity = utils . random_unicode ( ) <EOL> args = utils . random_unicode ( ) <EOL> change = utils . random_unicode ( ) <EOL> expected_pct = { "<STR_LIT:name>" : name , <EOL> "<STR_LIT>" : cooldown , <EOL> "<STR_LIT:type>" : ptype , <EOL> "<STR_LIT>" : desired_capacity , <EOL> "<STR_LIT:args>" : args <EOL> } <EOL> expected_nopct = expected_pct . copy ( ) <EOL> expected_pct [ "<STR_LIT>" ] = change <EOL> expected_nopct [ "<STR_LIT>" ] = change <EOL> ret_pct = mgr . _create_policy_body ( name , ptype , cooldown , change = change , <EOL> is_percent = True , desired_capacity = desired_capacity , args = args ) <EOL> ret_nopct = mgr . _create_policy_body ( name , ptype , cooldown , <EOL> change = change , is_percent = False , <EOL> desired_capacity = desired_capacity , args = args ) <EOL> self . assertEqual ( ret_nopct , expected_nopct ) <EOL> self . assertEqual ( ret_pct , expected_pct ) <EOL> def test_mgr_add_policy_desired_capacity ( self ) : <EOL> sg = self . scaling_group <EOL> mgr = sg . manager <EOL> ret_body = { "<STR_LIT>" : [ { } ] } <EOL> mgr . api . method_post = Mock ( return_value = ( None , ret_body ) ) <EOL> uri = "<STR_LIT>" % ( mgr . uri_base , sg . id ) <EOL> name = utils . random_unicode ( ) <EOL> ptype = utils . random_unicode ( ) <EOL> cooldown = utils . random_unicode ( ) <EOL> desired_capacity = utils . random_unicode ( ) <EOL> post_body = { <EOL> "<STR_LIT:name>" : name , <EOL> "<STR_LIT>" : cooldown , <EOL> "<STR_LIT:type>" : ptype , <EOL> "<STR_LIT>" : desired_capacity , <EOL> } <EOL> ret = mgr . add_policy ( sg , name , ptype , cooldown , <EOL> desired_capacity = desired_capacity ) <EOL> mgr . api . method_post . assert_called_with ( uri , body = [ post_body ] ) <EOL> self . assert_ ( isinstance ( ret , AutoScalePolicy ) ) <EOL> def test_mgr_list_policies ( self ) : <EOL> sg = self . scaling_group <EOL> mgr = sg . manager <EOL> ret_body = { "<STR_LIT>" : [ { } ] } <EOL> mgr . api . method_get = Mock ( return_value = ( None , ret_body ) ) <EOL> uri = "<STR_LIT>" % ( mgr . uri_base , sg . id ) <EOL> ret = mgr . list_policies ( sg ) <EOL> mgr . api . method_get . assert_called_once_with ( uri ) <EOL> def test_mgr_get_policy ( self ) : <EOL> sg = self . scaling_group <EOL> mgr = sg . manager <EOL> pol = utils . random_unicode ( ) <EOL> ret_body = { "<STR_LIT>" : { } } <EOL> uri = "<STR_LIT>" % ( mgr . uri_base , sg . id , pol ) <EOL> mgr . api . method_get = Mock ( return_value = ( None , ret_body ) ) <EOL> ret = mgr . get_policy ( sg , pol ) <EOL> self . assert_ ( isinstance ( ret , AutoScalePolicy ) ) <EOL> mgr . api . method_get . assert_called_once_with ( uri ) <EOL> def test_mgr_replace_policy ( self ) : <EOL> sg = self . scaling_group <EOL> mgr = sg . manager <EOL> pol_id = utils . random_unicode ( ) <EOL> info = { <EOL> "<STR_LIT:name>" : utils . random_unicode ( ) , <EOL> "<STR_LIT:type>" : utils . random_unicode ( ) , <EOL> "<STR_LIT>" : utils . random_unicode ( ) , <EOL> "<STR_LIT>" : utils . random_unicode ( ) , <EOL> "<STR_LIT:args>" : utils . random_unicode ( ) , <EOL> } <EOL> policy = fakes . FakeAutoScalePolicy ( mgr , info , sg ) <EOL> mgr . get_policy = Mock ( return_value = policy ) <EOL> new_name = utils . random_unicode ( ) <EOL> new_type = utils . random_unicode ( ) <EOL> new_cooldown = utils . random_unicode ( ) <EOL> new_change_percent = utils . random_unicode ( ) <EOL> mgr . api . method_put = Mock ( return_value = ( None , None ) ) <EOL> uri = "<STR_LIT>" % ( mgr . uri_base , sg . id , pol_id ) <EOL> expected = { <EOL> "<STR_LIT:name>" : new_name , <EOL> "<STR_LIT:type>" : new_type , <EOL> "<STR_LIT>" : new_cooldown , <EOL> "<STR_LIT>" : new_change_percent , <EOL> } <EOL> ret = mgr . replace_policy ( sg , pol_id , name = new_name , <EOL> policy_type = new_type , cooldown = new_cooldown , <EOL> change = new_change_percent , is_percent = True ) <EOL> mgr . api . method_put . assert_called_with ( uri , body = expected ) <EOL> def test_mgr_update_policy ( self ) : <EOL> sg = self . scaling_group <EOL> mgr = sg . manager <EOL> pol = utils . random_unicode ( ) <EOL> name = utils . random_unicode ( ) <EOL> ptype = utils . random_unicode ( ) <EOL> cooldown = utils . random_unicode ( ) <EOL> change = utils . random_unicode ( ) <EOL> args = utils . random_unicode ( ) <EOL> mgr . get_policy = Mock ( return_value = fakes . FakeAutoScalePolicy ( mgr , { } , <EOL> sg ) ) <EOL> mgr . api . method_put = Mock ( return_value = ( None , None ) ) <EOL> uri = "<STR_LIT>" % ( mgr . uri_base , sg . id , pol ) <EOL> for is_percent in ( True , False ) : <EOL> put_body = { "<STR_LIT:name>" : name , "<STR_LIT>" : cooldown , "<STR_LIT:type>" : ptype , <EOL> "<STR_LIT:args>" : args } <EOL> if is_percent : <EOL> put_body [ "<STR_LIT>" ] = change <EOL> else : <EOL> put_body [ "<STR_LIT>" ] = change <EOL> ret = mgr . update_policy ( sg , pol , name = name , policy_type = ptype , <EOL> cooldown = cooldown , change = change , is_percent = is_percent , <EOL> args = args ) <EOL> mgr . api . method_put . assert_called_with ( uri , body = put_body ) <EOL> def test_mgr_update_policy_desired_to_desired ( self ) : <EOL> sg = self . scaling_group <EOL> mgr = sg . manager <EOL> pol = utils . random_unicode ( ) <EOL> name = utils . random_unicode ( ) <EOL> ptype = utils . random_unicode ( ) <EOL> cooldown = utils . random_unicode ( ) <EOL> change = utils . random_unicode ( ) <EOL> args = utils . random_unicode ( ) <EOL> new_desired_capacity = <NUM_LIT:10> <EOL> old_info = { "<STR_LIT>" : <NUM_LIT:0> } <EOL> mgr . get_policy = Mock ( <EOL> return_value = fakes . FakeAutoScalePolicy ( mgr , old_info , sg ) ) <EOL> mgr . api . method_put = Mock ( return_value = ( None , None ) ) <EOL> uri = "<STR_LIT>" % ( mgr . uri_base , sg . id , pol ) <EOL> put_body = { "<STR_LIT:name>" : name , "<STR_LIT>" : cooldown , "<STR_LIT:type>" : ptype , <EOL> "<STR_LIT>" : new_desired_capacity } <EOL> ret = mgr . update_policy ( sg , pol , name = name , policy_type = ptype , <EOL> cooldown = cooldown , desired_capacity = new_desired_capacity ) <EOL> mgr . api . method_put . assert_called_with ( uri , body = put_body ) <EOL> def test_mgr_update_policy_change_to_desired ( self ) : <EOL> sg = self . scaling_group <EOL> mgr = sg . manager <EOL> pol = utils . random_unicode ( ) <EOL> name = utils . random_unicode ( ) <EOL> ptype = utils . random_unicode ( ) <EOL> cooldown = utils . random_unicode ( ) <EOL> change = utils . random_unicode ( ) <EOL> args = utils . random_unicode ( ) <EOL> new_desired_capacity = <NUM_LIT:10> <EOL> old_info = { "<STR_LIT>" : - <NUM_LIT:1> } <EOL> mgr . get_policy = Mock ( <EOL> return_value = fakes . FakeAutoScalePolicy ( mgr , old_info , sg ) ) <EOL> mgr . api . method_put = Mock ( return_value = ( None , None ) ) <EOL> uri = "<STR_LIT>" % ( mgr . uri_base , sg . id , pol ) <EOL> put_body = { "<STR_LIT:name>" : name , "<STR_LIT>" : cooldown , "<STR_LIT:type>" : ptype , <EOL> "<STR_LIT>" : new_desired_capacity } <EOL> ret = mgr . update_policy ( sg , pol , name = name , policy_type = ptype , <EOL> cooldown = cooldown , desired_capacity = new_desired_capacity ) <EOL> mgr . api . method_put . assert_called_with ( uri , body = put_body ) <EOL> def test_mgr_update_policy_desired_to_change ( self ) : <EOL> sg = self . scaling_group <EOL> mgr = sg . manager <EOL> pol = utils . random_unicode ( ) <EOL> name = utils . random_unicode ( ) <EOL> ptype = utils . random_unicode ( ) <EOL> cooldown = utils . random_unicode ( ) <EOL> change = utils . random_unicode ( ) <EOL> args = utils . random_unicode ( ) <EOL> new_change = <NUM_LIT:1> <EOL> old_info = { "<STR_LIT>" : <NUM_LIT:0> } <EOL> mgr . get_policy = Mock ( <EOL> return_value = fakes . FakeAutoScalePolicy ( mgr , old_info , sg ) ) <EOL> mgr . api . method_put = Mock ( return_value = ( None , None ) ) <EOL> uri = "<STR_LIT>" % ( mgr . uri_base , sg . id , pol ) <EOL> put_body = { "<STR_LIT:name>" : name , "<STR_LIT>" : cooldown , "<STR_LIT:type>" : ptype , <EOL> "<STR_LIT>" : new_change } <EOL> ret = mgr . update_policy ( sg , pol , name = name , policy_type = ptype , <EOL> cooldown = cooldown , change = new_change ) <EOL> mgr . api . method_put . assert_called_with ( uri , body = put_body ) <EOL> def test_mgr_update_policy_maintain_desired_capacity ( self ) : <EOL> sg = self . scaling_group <EOL> mgr = sg . manager <EOL> pol = utils . random_unicode ( ) <EOL> name = utils . random_unicode ( ) <EOL> ptype = utils . random_unicode ( ) <EOL> cooldown = utils . random_unicode ( ) <EOL> change = utils . random_unicode ( ) <EOL> args = utils . random_unicode ( ) <EOL> new_name = utils . random_unicode ( ) <EOL> old_capacity = <NUM_LIT:0> <EOL> old_info = { <EOL> "<STR_LIT:type>" : ptype , <EOL> "<STR_LIT>" : old_capacity , <EOL> "<STR_LIT>" : cooldown , <EOL> } <EOL> mgr . get_policy = Mock ( <EOL> return_value = fakes . FakeAutoScalePolicy ( mgr , old_info , sg ) ) <EOL> mgr . api . method_put = Mock ( return_value = ( None , None ) ) <EOL> uri = "<STR_LIT>" % ( mgr . uri_base , sg . id , pol ) <EOL> put_body = { "<STR_LIT:name>" : new_name , "<STR_LIT>" : cooldown , "<STR_LIT:type>" : ptype , <EOL> "<STR_LIT>" : old_capacity } <EOL> ret = mgr . update_policy ( sg , pol , name = new_name ) <EOL> mgr . api . method_put . assert_called_with ( uri , body = put_body ) <EOL> def test_mgr_update_policy_maintain_is_percent ( self ) : <EOL> sg = self . scaling_group <EOL> mgr = sg . manager <EOL> pol = utils . random_unicode ( ) <EOL> name = utils . random_unicode ( ) <EOL> ptype = utils . random_unicode ( ) <EOL> cooldown = utils . random_unicode ( ) <EOL> new_name = utils . random_unicode ( ) <EOL> old_percent = <NUM_LIT:10> <EOL> old_info = { <EOL> "<STR_LIT:type>" : ptype , <EOL> "<STR_LIT>" : old_percent , <EOL> "<STR_LIT>" : cooldown , <EOL> } <EOL> mgr . get_policy = Mock ( <EOL> return_value = fakes . FakeAutoScalePolicy ( mgr , old_info , sg ) ) <EOL> mgr . api . method_put = Mock ( return_value = ( None , None ) ) <EOL> uri = "<STR_LIT>" % ( mgr . uri_base , sg . id , pol ) <EOL> put_body = { "<STR_LIT:name>" : new_name , "<STR_LIT>" : cooldown , "<STR_LIT:type>" : ptype , <EOL> "<STR_LIT>" : old_percent } <EOL> ret = mgr . update_policy ( sg , pol , name = new_name ) <EOL> mgr . api . method_put . assert_called_with ( uri , body = put_body ) <EOL> def test_mgr_update_policy_maintain_is_absolute ( self ) : <EOL> sg = self . scaling_group <EOL> mgr = sg . manager <EOL> pol = utils . random_unicode ( ) <EOL> name = utils . random_unicode ( ) <EOL> ptype = utils . random_unicode ( ) <EOL> cooldown = utils . random_unicode ( ) <EOL> change = utils . random_unicode ( ) <EOL> new_name = utils . random_unicode ( ) <EOL> old_change = <NUM_LIT:10> <EOL> old_info = { <EOL> "<STR_LIT:type>" : ptype , <EOL> "<STR_LIT>" : old_change , <EOL> "<STR_LIT>" : cooldown , <EOL> } <EOL> mgr . get_policy = Mock ( <EOL> return_value = fakes . FakeAutoScalePolicy ( mgr , old_info , sg ) ) <EOL> mgr . api . method_put = Mock ( return_value = ( None , None ) ) <EOL> uri = "<STR_LIT>" % ( mgr . uri_base , sg . id , pol ) <EOL> put_body = { "<STR_LIT:name>" : new_name , "<STR_LIT>" : cooldown , "<STR_LIT:type>" : ptype , <EOL> "<STR_LIT>" : old_change } <EOL> ret = mgr . update_policy ( sg , pol , name = new_name ) <EOL> mgr . api . method_put . assert_called_with ( uri , body = put_body ) <EOL> def test_mgr_execute_policy ( self ) : <EOL> sg = self . scaling_group <EOL> mgr = sg . manager <EOL> pol = utils . random_unicode ( ) <EOL> uri = "<STR_LIT>" % ( mgr . uri_base , sg . id , pol ) <EOL> mgr . api . method_post = Mock ( return_value = ( None , None ) ) <EOL> mgr . execute_policy ( sg , pol ) <EOL> mgr . api . method_post . assert_called_once_with ( uri ) <EOL> def test_mgr_delete_policy ( self ) : <EOL> sg = self . scaling_group <EOL> mgr = sg . manager <EOL> pol = utils . random_unicode ( ) <EOL> uri = "<STR_LIT>" % ( mgr . uri_base , sg . id , pol ) <EOL> mgr . api . method_delete = Mock ( return_value = ( None , None ) ) <EOL> mgr . delete_policy ( sg , pol ) <EOL> mgr . api . method_delete . assert_called_once_with ( uri ) <EOL> def test_mgr_add_webhook ( self ) : <EOL> sg = self . scaling_group <EOL> mgr = sg . manager <EOL> pol = utils . random_unicode ( ) <EOL> ret_body = { "<STR_LIT>" : [ { } ] } <EOL> mgr . api . method_post = Mock ( return_value = ( None , ret_body ) ) <EOL> uri = "<STR_LIT>" % ( mgr . uri_base , sg . id , pol ) <EOL> mgr . get_policy = Mock ( return_value = fakes . FakeAutoScalePolicy ( mgr , { } , <EOL> sg ) ) <EOL> name = utils . random_unicode ( ) <EOL> metadata = utils . random_unicode ( ) <EOL> post_body = { "<STR_LIT:name>" : name , "<STR_LIT>" : metadata } <EOL> ret = mgr . add_webhook ( sg , pol , name , metadata = metadata ) <EOL> mgr . api . method_post . assert_called_with ( uri , body = [ post_body ] ) <EOL> self . assert_ ( isinstance ( ret , AutoScaleWebhook ) ) <EOL> def test_mgr_list_webhooks ( self ) : <EOL> sg = self . scaling_group <EOL> mgr = sg . manager <EOL> pol = fakes . FakeAutoScalePolicy ( mgr , { } , sg ) <EOL> ret_body = { "<STR_LIT>" : [ { } ] } <EOL> mgr . api . method_get = Mock ( return_value = ( None , ret_body ) ) <EOL> mgr . get_policy = Mock ( return_value = fakes . FakeAutoScalePolicy ( mgr , { } , <EOL> sg ) ) <EOL> uri = "<STR_LIT>" % ( mgr . uri_base , sg . id , pol . id ) <EOL> ret = mgr . list_webhooks ( sg , pol ) <EOL> mgr . api . method_get . assert_called_once_with ( uri ) <EOL> def test_mgr_get_webhook ( self ) : <EOL> sg = self . scaling_group <EOL> mgr = sg . manager <EOL> pol = fakes . FakeAutoScalePolicy ( mgr , { } , sg ) <EOL> hook = utils . random_unicode ( ) <EOL> ret_body = { "<STR_LIT>" : { } } <EOL> uri = "<STR_LIT>" % ( mgr . uri_base , sg . id , pol . id , <EOL> hook ) <EOL> mgr . api . method_get = Mock ( return_value = ( None , ret_body ) ) <EOL> ret = mgr . get_webhook ( sg , pol , hook ) <EOL> self . assert_ ( isinstance ( ret , AutoScaleWebhook ) ) <EOL> mgr . api . method_get . assert_called_once_with ( uri ) <EOL> def test_mgr_replace_webhook ( self ) : <EOL> sg = self . scaling_group <EOL> mgr = sg . manager <EOL> pol = fakes . FakeAutoScalePolicy ( mgr , { } , sg ) <EOL> hook = utils . random_unicode ( ) <EOL> info = { "<STR_LIT:name>" : utils . random_unicode ( ) , <EOL> "<STR_LIT>" : utils . random_unicode ( ) } <EOL> hook_obj = fakes . FakeAutoScaleWebhook ( mgr , info , pol , sg ) <EOL> new_name = utils . random_unicode ( ) <EOL> new_metadata = utils . random_unicode ( ) <EOL> mgr . get_webhook = Mock ( return_value = hook_obj ) <EOL> mgr . api . method_put = Mock ( return_value = ( None , None ) ) <EOL> uri = "<STR_LIT>" % ( mgr . uri_base , sg . id , pol . id , <EOL> hook ) <EOL> expected = { "<STR_LIT:name>" : new_name , "<STR_LIT>" : { } } <EOL> ret = mgr . replace_webhook ( sg , pol , hook , name = new_name ) <EOL> mgr . api . method_put . assert_called_with ( uri , body = expected ) <EOL> def test_mgr_update_webhook ( self ) : <EOL> sg = self . scaling_group <EOL> mgr = sg . manager <EOL> pol = fakes . FakeAutoScalePolicy ( mgr , { } , sg ) <EOL> hook = utils . random_unicode ( ) <EOL> hook_obj = fakes . FakeAutoScaleWebhook ( mgr , { } , pol , sg ) <EOL> name = utils . random_unicode ( ) <EOL> metadata = utils . random_unicode ( ) <EOL> mgr . get_webhook = Mock ( return_value = hook_obj ) <EOL> mgr . api . method_put = Mock ( return_value = ( None , None ) ) <EOL> uri = "<STR_LIT>" % ( mgr . uri_base , sg . id , pol . id , <EOL> hook ) <EOL> put_body = { "<STR_LIT:name>" : name , "<STR_LIT>" : metadata } <EOL> ret = mgr . update_webhook ( sg , pol , hook , name = name , metadata = metadata ) <EOL> mgr . api . method_put . assert_called_with ( uri , body = put_body ) <EOL> def test_mgr_update_webhook_metadata ( self ) : <EOL> sg = self . scaling_group <EOL> mgr = sg . manager <EOL> pol = fakes . FakeAutoScalePolicy ( mgr , { } , sg ) <EOL> hook = utils . random_unicode ( ) <EOL> hook_obj = fakes . FakeAutoScaleWebhook ( mgr , { } , pol , sg ) <EOL> hook_obj . metadata = { "<STR_LIT>" : "<STR_LIT>" } <EOL> metadata = { "<STR_LIT>" : "<STR_LIT>" } <EOL> expected = hook_obj . metadata . copy ( ) <EOL> expected . update ( metadata ) <EOL> uri = "<STR_LIT>" % ( mgr . uri_base , sg . id , pol . id , <EOL> hook ) <EOL> mgr . update_webhook = Mock ( ) <EOL> mgr . get_webhook = Mock ( return_value = hook_obj ) <EOL> mgr . update_webhook_metadata ( sg , pol , hook , metadata ) <EOL> mgr . update_webhook . assert_called_once_with ( sg , pol , hook_obj , <EOL> metadata = expected ) <EOL> def test_mgr_delete_webhook ( self ) : <EOL> sg = self . scaling_group <EOL> mgr = sg . manager <EOL> pol = fakes . FakeAutoScalePolicy ( mgr , { } , sg ) <EOL> hook = utils . random_unicode ( ) <EOL> hook_obj = fakes . FakeAutoScaleWebhook ( mgr , { } , pol , sg ) <EOL> uri = "<STR_LIT>" % ( mgr . uri_base , sg . id , pol . id , <EOL> hook ) <EOL> mgr . api . method_delete = Mock ( return_value = ( None , None ) ) <EOL> mgr . get_webhook = Mock ( return_value = hook_obj ) <EOL> mgr . delete_webhook ( sg , pol , hook ) <EOL> mgr . api . method_delete . assert_called_once_with ( uri ) <EOL> def test_mgr_resolve_lbs_dict ( self ) : <EOL> sg = self . scaling_group <EOL> mgr = sg . manager <EOL> key = utils . random_unicode ( ) <EOL> val = utils . random_unicode ( ) <EOL> lb_dict = { key : val } <EOL> ret = mgr . _resolve_lbs ( lb_dict ) <EOL> self . assertEqual ( ret , [ lb_dict ] ) <EOL> def test_mgr_resolve_lbs_clb ( self ) : <EOL> sg = self . scaling_group <EOL> mgr = sg . manager <EOL> clb = fakes . FakeLoadBalancer ( None , { } ) <EOL> ret = mgr . _resolve_lbs ( clb ) <EOL> expected = { "<STR_LIT>" : clb . id , "<STR_LIT:port>" : clb . port } <EOL> self . assertEqual ( ret , [ expected ] ) <EOL> def test_mgr_resolve_lbs_tuple ( self ) : <EOL> sg = self . scaling_group <EOL> mgr = sg . manager <EOL> fake_id = utils . random_unicode ( ) <EOL> fake_port = utils . random_unicode ( ) <EOL> lbs = ( fake_id , fake_port ) <EOL> ret = mgr . _resolve_lbs ( lbs ) <EOL> expected = { "<STR_LIT>" : fake_id , "<STR_LIT:port>" : fake_port } <EOL> self . assertEqual ( ret , [ expected ] ) <EOL> def test_mgr_resolve_lbs_id ( self ) : <EOL> sg = self . scaling_group <EOL> mgr = sg . manager <EOL> clb = fakes . FakeLoadBalancer ( None , { } ) <EOL> sav = pyrax . cloud_loadbalancers <EOL> class PyrCLB ( object ) : <EOL> def get ( self , * args , ** kwargs ) : <EOL> return clb <EOL> pyrax . cloud_loadbalancers = PyrCLB ( ) <EOL> ret = mgr . _resolve_lbs ( "<STR_LIT>" ) <EOL> expected = { "<STR_LIT>" : clb . id , "<STR_LIT:port>" : clb . port } <EOL> self . assertEqual ( ret , [ expected ] ) <EOL> pyrax . cloud_loadbalancers = sav <EOL> def test_mgr_resolve_lbs_id_fail ( self ) : <EOL> sg = self . scaling_group <EOL> mgr = sg . manager <EOL> pyclb = pyrax . cloudloadbalancers <EOL> pyclb . get = Mock ( side_effect = Exception ( ) ) <EOL> self . assertRaises ( exc . InvalidLoadBalancer , mgr . _resolve_lbs , "<STR_LIT>" ) <EOL> def test_mgr_create_body ( self ) : <EOL> sg = self . scaling_group <EOL> mgr = sg . manager <EOL> name = utils . random_unicode ( ) <EOL> cooldown = utils . random_unicode ( ) <EOL> min_entities = utils . random_unicode ( ) <EOL> max_entities = utils . random_unicode ( ) <EOL> launch_config_type = utils . random_unicode ( ) <EOL> flavor = utils . random_unicode ( ) <EOL> disk_config = None <EOL> metadata = None <EOL> personality = [ { "<STR_LIT:path>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" } ] <EOL> scaling_policies = None <EOL> networks = utils . random_unicode ( ) <EOL> lb = fakes . FakeLoadBalancer ( ) <EOL> load_balancers = ( lb . id , lb . port ) <EOL> server_name = utils . random_unicode ( ) <EOL> image = utils . random_unicode ( ) <EOL> group_metadata = utils . random_unicode ( ) <EOL> key_name = utils . random_unicode ( ) <EOL> expected = { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : cooldown , <EOL> "<STR_LIT>" : max_entities , <EOL> "<STR_LIT>" : min_entities , <EOL> "<STR_LIT:name>" : name , <EOL> "<STR_LIT>" : group_metadata } , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:args>" : { <EOL> "<STR_LIT>" : [ { "<STR_LIT>" : lb . id , <EOL> "<STR_LIT:port>" : lb . port } ] , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : flavor , <EOL> "<STR_LIT>" : image , <EOL> "<STR_LIT>" : { } , <EOL> "<STR_LIT:name>" : server_name , <EOL> "<STR_LIT>" : [ { "<STR_LIT:path>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" } ] , <EOL> "<STR_LIT>" : networks , <EOL> "<STR_LIT>" : key_name } <EOL> } , <EOL> "<STR_LIT:type>" : launch_config_type } , <EOL> "<STR_LIT>" : [ ] } <EOL> self . maxDiff = <NUM_LIT> <EOL> ret = mgr . _create_body ( name , cooldown , min_entities , max_entities , <EOL> launch_config_type , server_name , image , flavor , <EOL> disk_config = disk_config , metadata = metadata , <EOL> personality = personality , networks = networks , <EOL> load_balancers = load_balancers , <EOL> scaling_policies = scaling_policies , <EOL> group_metadata = group_metadata , key_name = key_name ) <EOL> self . assertEqual ( ret , expected ) <EOL> def test_mgr_create_body_disk_config ( self ) : <EOL> sg = self . scaling_group <EOL> mgr = sg . manager <EOL> name = utils . random_unicode ( ) <EOL> cooldown = utils . random_unicode ( ) <EOL> min_entities = utils . random_unicode ( ) <EOL> max_entities = utils . random_unicode ( ) <EOL> launch_config_type = utils . random_unicode ( ) <EOL> flavor = utils . random_unicode ( ) <EOL> disk_config = utils . random_unicode ( ) <EOL> metadata = None <EOL> personality = None <EOL> scaling_policies = None <EOL> networks = utils . random_unicode ( ) <EOL> lb = fakes . FakeLoadBalancer ( ) <EOL> load_balancers = ( lb . id , lb . port ) <EOL> server_name = utils . random_unicode ( ) <EOL> image = utils . random_unicode ( ) <EOL> group_metadata = utils . random_unicode ( ) <EOL> key_name = utils . random_unicode ( ) <EOL> expected = { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : cooldown , <EOL> "<STR_LIT>" : max_entities , <EOL> "<STR_LIT>" : min_entities , <EOL> "<STR_LIT:name>" : name , <EOL> "<STR_LIT>" : group_metadata } , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:args>" : { <EOL> "<STR_LIT>" : [ { "<STR_LIT>" : lb . id , <EOL> "<STR_LIT:port>" : lb . port } ] , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : disk_config , <EOL> "<STR_LIT>" : flavor , <EOL> "<STR_LIT>" : image , <EOL> "<STR_LIT>" : { } , <EOL> "<STR_LIT:name>" : server_name , <EOL> "<STR_LIT>" : networks , <EOL> "<STR_LIT>" : key_name } <EOL> } , <EOL> "<STR_LIT:type>" : launch_config_type } , <EOL> "<STR_LIT>" : [ ] } <EOL> self . maxDiff = <NUM_LIT> <EOL> ret = mgr . _create_body ( name , cooldown , min_entities , max_entities , <EOL> launch_config_type , server_name , image , flavor , <EOL> disk_config = disk_config , metadata = metadata , <EOL> personality = personality , networks = networks , <EOL> load_balancers = load_balancers , <EOL> scaling_policies = scaling_policies , <EOL> group_metadata = group_metadata , key_name = key_name ) <EOL> self . assertEqual ( ret , expected ) <EOL> def test_policy_init ( self ) : <EOL> sg = self . scaling_group <EOL> mgr = sg . manager <EOL> mgr . get = Mock ( return_value = sg ) <EOL> pol = fakes . FakeAutoScalePolicy ( mgr , { } , sg . id ) <EOL> self . assert_ ( pol . scaling_group is sg ) <EOL> def test_policy_get ( self ) : <EOL> sg = self . scaling_group <EOL> mgr = sg . manager <EOL> pol = fakes . FakeAutoScalePolicy ( mgr , { } , sg ) <EOL> mgr . get_policy = Mock ( return_value = pol ) <EOL> pol . get ( ) <EOL> mgr . get_policy . assert_called_once_with ( sg , pol ) <EOL> def test_policy_delete ( self ) : <EOL> sg = self . scaling_group <EOL> mgr = sg . manager <EOL> pol = fakes . FakeAutoScalePolicy ( mgr , { } , sg ) <EOL> mgr . delete_policy = Mock ( ) <EOL> pol . delete ( ) <EOL> mgr . delete_policy . assert_called_once_with ( sg , pol ) <EOL> def test_policy_update ( self ) : <EOL> sg = self . scaling_group <EOL> mgr = sg . manager <EOL> pol = fakes . FakeAutoScalePolicy ( mgr , { } , sg ) <EOL> name = utils . random_unicode ( ) <EOL> policy_type = utils . random_unicode ( ) <EOL> cooldown = utils . random_unicode ( ) <EOL> change = utils . random_unicode ( ) <EOL> is_percent = utils . random_unicode ( ) <EOL> desired_capacity = utils . random_unicode ( ) <EOL> args = utils . random_unicode ( ) <EOL> mgr . update_policy = Mock ( ) <EOL> pol . update ( name = name , policy_type = policy_type , cooldown = cooldown , <EOL> change = change , is_percent = is_percent , <EOL> desired_capacity = desired_capacity , args = args ) <EOL> mgr . update_policy . assert_called_once_with ( scaling_group = sg , <EOL> policy = pol , name = name , policy_type = policy_type , <EOL> cooldown = cooldown , change = change , is_percent = is_percent , <EOL> desired_capacity = desired_capacity , args = args ) <EOL> def test_policy_execute ( self ) : <EOL> sg = self . scaling_group <EOL> mgr = sg . manager <EOL> pol = fakes . FakeAutoScalePolicy ( mgr , { } , sg ) <EOL> mgr . execute_policy = Mock ( ) <EOL> pol . execute ( ) <EOL> mgr . execute_policy . assert_called_once_with ( sg , pol ) <EOL> def test_policy_add_webhook ( self ) : <EOL> sg = self . scaling_group <EOL> mgr = sg . manager <EOL> pol = fakes . FakeAutoScalePolicy ( mgr , { } , sg ) <EOL> mgr . add_webhook = Mock ( ) <EOL> name = utils . random_unicode ( ) <EOL> metadata = utils . random_unicode ( ) <EOL> pol . add_webhook ( name , metadata = metadata ) <EOL> mgr . add_webhook . assert_called_once_with ( sg , pol , name , <EOL> metadata = metadata ) <EOL> def test_policy_list_webhooks ( self ) : <EOL> sg = self . scaling_group <EOL> mgr = sg . manager <EOL> pol = fakes . FakeAutoScalePolicy ( mgr , { } , sg ) <EOL> mgr . list_webhooks = Mock ( ) <EOL> pol . list_webhooks ( ) <EOL> mgr . list_webhooks . assert_called_once_with ( sg , pol ) <EOL> def test_policy_get_webhook ( self ) : <EOL> sg = self . scaling_group <EOL> mgr = sg . manager <EOL> pol = fakes . FakeAutoScalePolicy ( mgr , { } , sg ) <EOL> hook = utils . random_unicode ( ) <EOL> mgr . get_webhook = Mock ( ) <EOL> pol . get_webhook ( hook ) <EOL> mgr . get_webhook . assert_called_once_with ( sg , pol , hook ) <EOL> def test_policy_update_webhook ( self ) : <EOL> sg = self . scaling_group <EOL> mgr = sg . manager <EOL> pol = fakes . FakeAutoScalePolicy ( mgr , { } , sg ) <EOL> hook = utils . random_unicode ( ) <EOL> name = utils . random_unicode ( ) <EOL> metadata = utils . random_unicode ( ) <EOL> mgr . update_webhook = Mock ( ) <EOL> pol . update_webhook ( hook , name = name , metadata = metadata ) <EOL> mgr . update_webhook . assert_called_once_with ( sg , policy = pol , webhook = hook , <EOL> name = name , metadata = metadata ) <EOL> def test_policy_update_webhook_metadata ( self ) : <EOL> sg = self . scaling_group <EOL> mgr = sg . manager <EOL> pol = fakes . FakeAutoScalePolicy ( mgr , { } , sg ) <EOL> hook = utils . random_unicode ( ) <EOL> metadata = utils . random_unicode ( ) <EOL> mgr . update_webhook_metadata = Mock ( ) <EOL> pol . update_webhook_metadata ( hook , metadata = metadata ) <EOL> mgr . update_webhook_metadata . assert_called_once_with ( sg , pol , hook , <EOL> metadata ) <EOL> def test_policy_delete_webhook ( self ) : <EOL> sg = self . scaling_group <EOL> mgr = sg . manager <EOL> pol = fakes . FakeAutoScalePolicy ( mgr , { } , sg ) <EOL> hook = utils . random_unicode ( ) <EOL> mgr . delete_webhook = Mock ( ) <EOL> pol . delete_webhook ( hook ) <EOL> mgr . delete_webhook . assert_called_once_with ( sg , pol , hook ) <EOL> def test_webhook_get ( self ) : <EOL> sg = self . scaling_group <EOL> mgr = sg . manager <EOL> pol = fakes . FakeAutoScalePolicy ( mgr , { } , sg ) <EOL> hook = fakes . FakeAutoScaleWebhook ( mgr , { } , pol , sg ) <EOL> pol . get_webhook = Mock ( ) <EOL> hook . get ( ) <EOL> pol . get_webhook . assert_called_once_with ( hook ) <EOL> def test_webhook_update ( self ) : <EOL> sg = self . scaling_group <EOL> mgr = sg . manager <EOL> pol = fakes . FakeAutoScalePolicy ( mgr , { } , sg ) <EOL> hook = fakes . FakeAutoScaleWebhook ( mgr , { } , pol , sg ) <EOL> name = utils . random_unicode ( ) <EOL> metadata = utils . random_unicode ( ) <EOL> pol . update_webhook = Mock ( ) <EOL> hook . update ( name = name , metadata = metadata ) <EOL> pol . update_webhook . assert_called_once_with ( hook , name = name , <EOL> metadata = metadata ) <EOL> def test_webhook_update_metadata ( self ) : <EOL> sg = self . scaling_group <EOL> mgr = sg . manager <EOL> pol = fakes . FakeAutoScalePolicy ( mgr , { } , sg ) <EOL> hook = fakes . FakeAutoScaleWebhook ( mgr , { } , pol , sg ) <EOL> metadata = utils . random_unicode ( ) <EOL> pol . update_webhook_metadata = Mock ( ) <EOL> hook . update_metadata ( metadata = metadata ) <EOL> pol . update_webhook_metadata . assert_called_once_with ( hook , <EOL> metadata ) <EOL> def test_webhook_delete ( self ) : <EOL> sg = self . scaling_group <EOL> mgr = sg . manager <EOL> pol = fakes . FakeAutoScalePolicy ( mgr , { } , sg ) <EOL> hook = fakes . FakeAutoScaleWebhook ( mgr , { } , pol , sg ) <EOL> pol . delete_webhook = Mock ( ) <EOL> hook . delete ( ) <EOL> pol . delete_webhook . assert_called_once_with ( hook ) <EOL> def test_clt_get_state ( self ) : <EOL> clt = fakes . FakeAutoScaleClient ( ) <EOL> sg = self . scaling_group <EOL> mgr = clt . _manager <EOL> mgr . get_state = Mock ( ) <EOL> clt . get_state ( sg ) <EOL> mgr . get_state . assert_called_once_with ( sg ) <EOL> def test_clt_pause ( self ) : <EOL> clt = fakes . FakeAutoScaleClient ( ) <EOL> sg = self . scaling_group <EOL> mgr = clt . _manager <EOL> mgr . pause = Mock ( ) <EOL> clt . pause ( sg ) <EOL> mgr . pause . assert_called_once_with ( sg ) <EOL> def test_clt_resume ( self ) : <EOL> clt = fakes . FakeAutoScaleClient ( ) <EOL> mgr = clt . _manager <EOL> sg = self . scaling_group <EOL> mgr . resume = Mock ( ) <EOL> clt . resume ( sg ) <EOL> mgr . resume . assert_called_once_with ( sg ) <EOL> def test_clt_replace ( self ) : <EOL> clt = fakes . FakeAutoScaleClient ( ) <EOL> mgr = clt . _manager <EOL> sg = self . scaling_group <EOL> name = utils . random_unicode ( ) <EOL> cooldown = utils . random_unicode ( ) <EOL> min_entities = utils . random_unicode ( ) <EOL> max_entities = utils . random_unicode ( ) <EOL> metadata = utils . random_unicode ( ) <EOL> mgr . replace = Mock ( ) <EOL> clt . replace ( sg , name , cooldown , min_entities , max_entities , <EOL> metadata = metadata ) <EOL> mgr . replace . assert_called_once_with ( sg , name , cooldown , min_entities , <EOL> max_entities , metadata = metadata ) <EOL> def test_clt_update ( self ) : <EOL> clt = fakes . FakeAutoScaleClient ( ) <EOL> mgr = clt . _manager <EOL> sg = self . scaling_group <EOL> name = utils . random_unicode ( ) <EOL> cooldown = utils . random_unicode ( ) <EOL> min_entities = utils . random_unicode ( ) <EOL> max_entities = utils . random_unicode ( ) <EOL> metadata = utils . random_unicode ( ) <EOL> mgr . update = Mock ( ) <EOL> clt . update ( sg , name = name , cooldown = cooldown , min_entities = min_entities , <EOL> max_entities = max_entities , metadata = metadata ) <EOL> mgr . update . assert_called_once_with ( sg , name = name , cooldown = cooldown , <EOL> min_entities = min_entities , max_entities = max_entities , <EOL> metadata = metadata ) <EOL> def test_clt_update_metadata ( self ) : <EOL> clt = fakes . FakeAutoScaleClient ( ) <EOL> mgr = clt . _manager <EOL> sg = self . scaling_group <EOL> metadata = utils . random_unicode ( ) <EOL> mgr . update_metadata = Mock ( ) <EOL> clt . update_metadata ( sg , metadata ) <EOL> mgr . update_metadata . assert_called_once_with ( sg , metadata ) <EOL> def test_clt_get_configuration ( self ) : <EOL> clt = fakes . FakeAutoScaleClient ( ) <EOL> mgr = clt . _manager <EOL> sg = self . scaling_group <EOL> mgr . get_configuration = Mock ( ) <EOL> clt . get_configuration ( sg ) <EOL> mgr . get_configuration . assert_called_once_with ( sg ) <EOL> def test_clt_get_launch_config ( self ) : <EOL> clt = fakes . FakeAutoScaleClient ( ) <EOL> mgr = clt . _manager <EOL> sg = self . scaling_group <EOL> mgr . get_launch_config = Mock ( ) <EOL> clt . get_launch_config ( sg ) <EOL> mgr . get_launch_config . assert_called_once_with ( sg ) <EOL> def test_clt_replace_launch_config ( self ) : <EOL> clt = fakes . FakeAutoScaleClient ( ) <EOL> mgr = clt . _manager <EOL> sg = self . scaling_group <EOL> mgr . replace_launch_config = Mock ( ) <EOL> launch_config_type = utils . random_unicode ( ) <EOL> server_name = utils . random_unicode ( ) <EOL> image = utils . random_unicode ( ) <EOL> flavor = utils . random_unicode ( ) <EOL> disk_config = utils . random_unicode ( ) <EOL> metadata = utils . random_unicode ( ) <EOL> personality = utils . random_unicode ( ) <EOL> networks = utils . random_unicode ( ) <EOL> load_balancers = utils . random_unicode ( ) <EOL> key_name = utils . random_unicode ( ) <EOL> clt . replace_launch_config ( sg , launch_config_type , server_name , image , <EOL> flavor , disk_config = disk_config , metadata = metadata , <EOL> personality = personality , networks = networks , <EOL> load_balancers = load_balancers , key_name = key_name ) <EOL> mgr . replace_launch_config . assert_called_once_with ( sg , <EOL> launch_config_type , server_name , image , flavor , <EOL> disk_config = disk_config , metadata = metadata , <EOL> personality = personality , networks = networks , <EOL> load_balancers = load_balancers , key_name = key_name ) <EOL> def test_clt_update_launch_config ( self ) : <EOL> clt = fakes . FakeAutoScaleClient ( ) <EOL> mgr = clt . _manager <EOL> sg = self . scaling_group <EOL> mgr . update_launch_config = Mock ( ) <EOL> server_name = utils . random_unicode ( ) <EOL> flavor = utils . random_unicode ( ) <EOL> image = utils . random_unicode ( ) <EOL> disk_config = utils . random_unicode ( ) <EOL> metadata = utils . random_unicode ( ) <EOL> personality = utils . random_unicode ( ) <EOL> networks = utils . random_unicode ( ) <EOL> load_balancers = utils . random_unicode ( ) <EOL> key_name = utils . random_unicode ( ) <EOL> user_data = utils . random_unicode ( ) <EOL> config_drive = utils . random_unicode ( ) <EOL> clt . update_launch_config ( sg , server_name = server_name , flavor = flavor , <EOL> image = image , disk_config = disk_config , metadata = metadata , <EOL> personality = personality , networks = networks , <EOL> load_balancers = load_balancers , key_name = key_name , <EOL> config_drive = config_drive , user_data = user_data ) <EOL> mgr . update_launch_config . assert_called_once_with ( sg , <EOL> server_name = server_name , flavor = flavor , image = image , <EOL> disk_config = disk_config , metadata = metadata , <EOL> personality = personality , networks = networks , <EOL> load_balancers = load_balancers , key_name = key_name , <EOL> config_drive = config_drive , user_data = user_data ) <EOL> def test_clt_update_launch_metadata ( self ) : <EOL> clt = fakes . FakeAutoScaleClient ( ) <EOL> mgr = clt . _manager <EOL> sg = self . scaling_group <EOL> mgr . update_launch_metadata = Mock ( ) <EOL> metadata = utils . random_unicode ( ) <EOL> clt . update_launch_metadata ( sg , metadata ) <EOL> mgr . update_launch_metadata . assert_called_once_with ( sg , metadata ) <EOL> def test_clt_add_policy ( self ) : <EOL> clt = fakes . FakeAutoScaleClient ( ) <EOL> mgr = clt . _manager <EOL> sg = self . scaling_group <EOL> name = utils . random_unicode ( ) <EOL> policy_type = utils . random_unicode ( ) <EOL> cooldown = utils . random_unicode ( ) <EOL> change = utils . random_unicode ( ) <EOL> is_percent = utils . random_unicode ( ) <EOL> desired_capacity = utils . random_unicode ( ) <EOL> args = utils . random_unicode ( ) <EOL> mgr . add_policy = Mock ( ) <EOL> clt . add_policy ( sg , name , policy_type , cooldown , change , <EOL> is_percent = is_percent , desired_capacity = desired_capacity , <EOL> args = args ) <EOL> mgr . add_policy . assert_called_once_with ( sg , name , policy_type , cooldown , <EOL> change = change , is_percent = is_percent , <EOL> desired_capacity = desired_capacity , args = args ) <EOL> def test_clt_list_policies ( self ) : <EOL> clt = fakes . FakeAutoScaleClient ( ) <EOL> mgr = clt . _manager <EOL> sg = self . scaling_group <EOL> mgr . list_policies = Mock ( ) <EOL> clt . list_policies ( sg ) <EOL> mgr . list_policies . assert_called_once_with ( sg ) <EOL> def test_clt_get_policy ( self ) : <EOL> clt = fakes . FakeAutoScaleClient ( ) <EOL> mgr = clt . _manager <EOL> sg = self . scaling_group <EOL> pol = utils . random_unicode ( ) <EOL> mgr . get_policy = Mock ( ) <EOL> clt . get_policy ( sg , pol ) <EOL> mgr . get_policy . assert_called_once_with ( sg , pol ) <EOL> def test_clt_replace_policy ( self ) : <EOL> clt = fakes . FakeAutoScaleClient ( ) <EOL> mgr = clt . _manager <EOL> sg = self . scaling_group <EOL> pol = utils . random_unicode ( ) <EOL> name = utils . random_unicode ( ) <EOL> policy_type = utils . random_unicode ( ) <EOL> cooldown = utils . random_unicode ( ) <EOL> change = utils . random_unicode ( ) <EOL> is_percent = utils . random_unicode ( ) <EOL> desired_capacity = utils . random_unicode ( ) <EOL> args = utils . random_unicode ( ) <EOL> mgr . replace_policy = Mock ( ) <EOL> clt . replace_policy ( sg , pol , name , policy_type , cooldown , change = change , <EOL> is_percent = is_percent , desired_capacity = desired_capacity , <EOL> args = args ) <EOL> mgr . replace_policy . assert_called_once_with ( sg , pol , name , policy_type , <EOL> cooldown , change = change , is_percent = is_percent , <EOL> desired_capacity = desired_capacity , args = args ) <EOL> def test_clt_update_policy ( self ) : <EOL> clt = fakes . FakeAutoScaleClient ( ) <EOL> mgr = clt . _manager <EOL> sg = self . scaling_group <EOL> pol = utils . random_unicode ( ) <EOL> name = utils . random_unicode ( ) <EOL> policy_type = utils . random_unicode ( ) <EOL> cooldown = utils . random_unicode ( ) <EOL> change = utils . random_unicode ( ) <EOL> is_percent = utils . random_unicode ( ) <EOL> desired_capacity = utils . random_unicode ( ) <EOL> args = utils . random_unicode ( ) <EOL> mgr . update_policy = Mock ( ) <EOL> clt . update_policy ( sg , pol , name = name , policy_type = policy_type , <EOL> cooldown = cooldown , change = change , is_percent = is_percent , <EOL> desired_capacity = desired_capacity , args = args ) <EOL> mgr . update_policy . assert_called_once_with ( sg , pol , name = name , <EOL> policy_type = policy_type , cooldown = cooldown , change = change , <EOL> is_percent = is_percent , desired_capacity = desired_capacity , <EOL> args = args ) <EOL> def test_clt_execute_policy ( self ) : <EOL> clt = fakes . FakeAutoScaleClient ( ) <EOL> mgr = clt . _manager <EOL> sg = self . scaling_group <EOL> pol = utils . random_unicode ( ) <EOL> mgr . execute_policy = Mock ( ) <EOL> clt . execute_policy ( sg , pol ) <EOL> mgr . execute_policy . assert_called_once_with ( scaling_group = sg , policy = pol ) <EOL> def test_clt_delete_policy ( self ) : <EOL> clt = fakes . FakeAutoScaleClient ( ) <EOL> mgr = clt . _manager <EOL> sg = self . scaling_group <EOL> pol = utils . random_unicode ( ) <EOL> mgr . delete_policy = Mock ( ) <EOL> clt . delete_policy ( sg , pol ) <EOL> mgr . delete_policy . assert_called_once_with ( scaling_group = sg , policy = pol ) <EOL> def test_clt_add_webhook ( self ) : <EOL> clt = fakes . FakeAutoScaleClient ( ) <EOL> mgr = clt . _manager <EOL> sg = self . scaling_group <EOL> pol = utils . random_unicode ( ) <EOL> name = utils . random_unicode ( ) <EOL> metadata = utils . random_unicode ( ) <EOL> mgr . add_webhook = Mock ( ) <EOL> clt . add_webhook ( sg , pol , name , metadata = metadata ) <EOL> mgr . add_webhook . assert_called_once_with ( sg , pol , name , <EOL> metadata = metadata ) <EOL> def test_clt_list_webhooks ( self ) : <EOL> clt = fakes . FakeAutoScaleClient ( ) <EOL> mgr = clt . _manager <EOL> sg = self . scaling_group <EOL> pol = utils . random_unicode ( ) <EOL> mgr . list_webhooks = Mock ( ) <EOL> clt . list_webhooks ( sg , pol ) <EOL> mgr . list_webhooks . assert_called_once_with ( sg , pol ) <EOL> def test_clt_get_webhook ( self ) : <EOL> clt = fakes . FakeAutoScaleClient ( ) <EOL> mgr = clt . _manager <EOL> sg = self . scaling_group <EOL> pol = utils . random_unicode ( ) <EOL> hook = utils . random_unicode ( ) <EOL> mgr . get_webhook = Mock ( ) <EOL> clt . get_webhook ( sg , pol , hook ) <EOL> mgr . get_webhook . assert_called_once_with ( sg , pol , hook ) <EOL> def test_clt_replace_webhook ( self ) : <EOL> clt = fakes . FakeAutoScaleClient ( ) <EOL> mgr = clt . _manager <EOL> sg = self . scaling_group <EOL> pol = utils . random_unicode ( ) <EOL> hook = utils . random_unicode ( ) <EOL> name = utils . random_unicode ( ) <EOL> metadata = utils . random_unicode ( ) <EOL> mgr . replace_webhook = Mock ( ) <EOL> clt . replace_webhook ( sg , pol , hook , name , metadata = metadata ) <EOL> mgr . replace_webhook . assert_called_once_with ( sg , pol , hook , name , <EOL> metadata = metadata ) <EOL> def test_clt_update_webhook ( self ) : <EOL> clt = fakes . FakeAutoScaleClient ( ) <EOL> mgr = clt . _manager <EOL> sg = self . scaling_group <EOL> pol = utils . random_unicode ( ) <EOL> hook = utils . random_unicode ( ) <EOL> name = utils . random_unicode ( ) <EOL> metadata = utils . random_unicode ( ) <EOL> mgr . update_webhook = Mock ( ) <EOL> clt . update_webhook ( sg , pol , hook , name = name , metadata = metadata ) <EOL> mgr . update_webhook . assert_called_once_with ( scaling_group = sg , policy = pol , <EOL> webhook = hook , name = name , metadata = metadata ) <EOL> def test_clt_update_webhook_metadata ( self ) : <EOL> clt = fakes . FakeAutoScaleClient ( ) <EOL> mgr = clt . _manager <EOL> sg = self . scaling_group <EOL> pol = utils . random_unicode ( ) <EOL> hook = utils . random_unicode ( ) <EOL> metadata = utils . random_unicode ( ) <EOL> mgr . update_webhook_metadata = Mock ( ) <EOL> clt . update_webhook_metadata ( sg , pol , hook , metadata ) <EOL> mgr . update_webhook_metadata . assert_called_once_with ( sg , pol , hook , <EOL> metadata ) <EOL> def test_clt_delete_webhook ( self ) : <EOL> clt = fakes . FakeAutoScaleClient ( ) <EOL> mgr = clt . _manager <EOL> sg = self . scaling_group <EOL> pol = utils . random_unicode ( ) <EOL> hook = utils . random_unicode ( ) <EOL> mgr . delete_webhook = Mock ( ) <EOL> clt . delete_webhook ( sg , pol , hook ) <EOL> mgr . delete_webhook . assert_called_once_with ( sg , pol , hook ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> unittest . main ( ) </s>
