<s> import ddt <EOL> import mock <EOL> from rally . plugins . openstack . scenarios . neutron import loadbalancer_v1 <EOL> from tests . unit import test <EOL> @ ddt . ddt <EOL> class NeutronLoadbalancerv1TestCase ( test . TestCase ) : <EOL> def _get_context ( self ) : <EOL> context = test . get_test_context ( ) <EOL> context . update ( { <EOL> "<STR_LIT:user>" : { <EOL> "<STR_LIT:id>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : mock . MagicMock ( ) <EOL> } , <EOL> "<STR_LIT>" : { "<STR_LIT:id>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : [ { "<STR_LIT:id>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : [ "<STR_LIT>" ] } ] } } ) <EOL> return context <EOL> @ ddt . data ( <EOL> { } , <EOL> { "<STR_LIT>" : None } , <EOL> { "<STR_LIT>" : { } } , <EOL> { "<STR_LIT>" : { "<STR_LIT:name>" : "<STR_LIT>" } } , <EOL> ) <EOL> @ ddt . unpack <EOL> def test_create_and_list_pools ( self , pool_create_args = None ) : <EOL> neutron_scenario = loadbalancer_v1 . NeutronLoadbalancerV1 ( <EOL> self . _get_context ( ) ) <EOL> pool_data = pool_create_args or { } <EOL> networks = self . _get_context ( ) [ "<STR_LIT>" ] [ "<STR_LIT>" ] <EOL> neutron_scenario . _create_v1_pools = mock . Mock ( ) <EOL> neutron_scenario . _list_v1_pools = mock . Mock ( ) <EOL> neutron_scenario . create_and_list_pools ( <EOL> pool_create_args = pool_create_args ) <EOL> neutron_scenario . _create_v1_pools . assert_called_once_with ( <EOL> networks , ** pool_data ) <EOL> neutron_scenario . _list_v1_pools . assert_called_once_with ( ) <EOL> @ ddt . data ( <EOL> { } , <EOL> { "<STR_LIT>" : None } , <EOL> { "<STR_LIT>" : { } } , <EOL> { "<STR_LIT>" : { "<STR_LIT:name>" : "<STR_LIT>" } } , <EOL> ) <EOL> @ ddt . unpack <EOL> def test_create_and_delete_pools ( self , pool_create_args = None ) : <EOL> neutron_scenario = loadbalancer_v1 . NeutronLoadbalancerV1 ( <EOL> self . _get_context ( ) ) <EOL> pools = [ { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:id>" : "<STR_LIT>" <EOL> } <EOL> } ] <EOL> pool_data = pool_create_args or { } <EOL> networks = self . _get_context ( ) [ "<STR_LIT>" ] [ "<STR_LIT>" ] <EOL> neutron_scenario . _create_v1_pools = mock . Mock ( return_value = pools ) <EOL> neutron_scenario . _delete_v1_pool = mock . Mock ( ) <EOL> neutron_scenario . create_and_delete_pools ( <EOL> pool_create_args = pool_create_args ) <EOL> self . assertEqual ( [ mock . call ( networks , ** pool_data ) ] , <EOL> neutron_scenario . _create_v1_pools . mock_calls ) <EOL> for pool in pools : <EOL> self . assertEqual ( <NUM_LIT:1> , neutron_scenario . _delete_v1_pool . call_count ) <EOL> @ ddt . data ( <EOL> { } , <EOL> { "<STR_LIT>" : None } , <EOL> { "<STR_LIT>" : { } } , <EOL> { "<STR_LIT>" : { "<STR_LIT:name>" : "<STR_LIT>" } } , <EOL> { "<STR_LIT>" : None } , <EOL> { "<STR_LIT>" : { } } , <EOL> { "<STR_LIT>" : { "<STR_LIT:name>" : "<STR_LIT>" } } , <EOL> { "<STR_LIT>" : None , "<STR_LIT>" : None } , <EOL> { "<STR_LIT>" : { "<STR_LIT:name>" : "<STR_LIT>" } , <EOL> "<STR_LIT>" : { "<STR_LIT:name>" : "<STR_LIT>" } } , <EOL> { "<STR_LIT>" : None , <EOL> "<STR_LIT>" : { "<STR_LIT:name>" : "<STR_LIT>" } } , <EOL> { "<STR_LIT>" : None , "<STR_LIT>" : { } } , <EOL> { "<STR_LIT>" : { } , "<STR_LIT>" : None } , <EOL> ) <EOL> @ ddt . unpack <EOL> def test_create_and_update_pools ( self , pool_create_args = None , <EOL> pool_update_args = None ) : <EOL> neutron_scenario = loadbalancer_v1 . NeutronLoadbalancerV1 ( <EOL> self . _get_context ( ) ) <EOL> pools = [ { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:id>" : "<STR_LIT>" <EOL> } <EOL> } ] <EOL> updated_pool = { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:id>" : "<STR_LIT>" , <EOL> "<STR_LIT:name>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : True <EOL> } <EOL> } <EOL> pool_data = pool_create_args or { } <EOL> pool_update_args = pool_update_args or { } <EOL> pool_update_args . update ( { "<STR_LIT:name>" : "<STR_LIT>" , "<STR_LIT>" : True } ) <EOL> neutron_scenario . _create_v1_pools = mock . Mock ( return_value = pools ) <EOL> neutron_scenario . _update_v1_pool = mock . Mock ( <EOL> return_value = updated_pool ) <EOL> networks = self . _get_context ( ) [ "<STR_LIT>" ] [ "<STR_LIT>" ] <EOL> neutron_scenario . create_and_update_pools ( <EOL> pool_create_args = pool_data , <EOL> pool_update_args = pool_update_args ) <EOL> self . assertEqual ( [ mock . call ( networks , ** pool_data ) ] , <EOL> neutron_scenario . _create_v1_pools . mock_calls ) <EOL> for pool in pools : <EOL> neutron_scenario . _update_v1_pool . assert_called_once_with ( <EOL> pool , ** pool_update_args ) <EOL> @ ddt . data ( <EOL> { } , <EOL> { "<STR_LIT>" : None } , <EOL> { "<STR_LIT>" : { } } , <EOL> { "<STR_LIT>" : { "<STR_LIT:name>" : "<STR_LIT>" } } , <EOL> { "<STR_LIT>" : None } , <EOL> { "<STR_LIT>" : { } } , <EOL> { "<STR_LIT>" : { "<STR_LIT:name>" : "<STR_LIT>" } } , <EOL> ) <EOL> @ ddt . unpack <EOL> def test_create_and_list_vips ( self , pool_create_args = None , <EOL> vip_create_args = None ) : <EOL> neutron_scenario = loadbalancer_v1 . NeutronLoadbalancerV1 ( <EOL> self . _get_context ( ) ) <EOL> pools = [ { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:id>" : "<STR_LIT>" <EOL> } <EOL> } ] <EOL> vip_data = vip_create_args or { } <EOL> pool_data = pool_create_args or { } <EOL> networks = self . _get_context ( ) [ "<STR_LIT>" ] [ "<STR_LIT>" ] <EOL> neutron_scenario . _create_v1_pools = mock . Mock ( return_value = pools ) <EOL> neutron_scenario . _create_v1_vip = mock . Mock ( ) <EOL> neutron_scenario . _list_v1_vips = mock . Mock ( ) <EOL> neutron_scenario . create_and_list_vips ( <EOL> pool_create_args = pool_create_args , vip_create_args = vip_create_args ) <EOL> neutron_scenario . _create_v1_pools . assert_called_once_with ( <EOL> networks , ** pool_data ) <EOL> neutron_scenario . _create_v1_vip . assert_has_calls ( <EOL> [ mock . call ( pool , ** vip_data ) for pool in pools ] ) <EOL> neutron_scenario . _list_v1_vips . assert_called_once_with ( ) <EOL> @ ddt . data ( <EOL> { } , <EOL> { "<STR_LIT>" : None } , <EOL> { "<STR_LIT>" : { } } , <EOL> { "<STR_LIT>" : { "<STR_LIT:name>" : "<STR_LIT>" } } , <EOL> { "<STR_LIT>" : None } , <EOL> { "<STR_LIT>" : { } } , <EOL> { "<STR_LIT>" : { "<STR_LIT:name>" : "<STR_LIT>" } } , <EOL> ) <EOL> @ ddt . unpack <EOL> def test_create_and_delete_vips ( self , pool_create_args = None , <EOL> vip_create_args = None ) : <EOL> pools = [ { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:id>" : "<STR_LIT>" <EOL> } <EOL> } ] <EOL> vip = { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:id>" : "<STR_LIT>" <EOL> } <EOL> } <EOL> neutron_scenario = loadbalancer_v1 . NeutronLoadbalancerV1 ( <EOL> self . _get_context ( ) ) <EOL> vip_data = vip_create_args or { } <EOL> pool_data = pool_create_args or { } <EOL> networks = self . _get_context ( ) [ "<STR_LIT>" ] [ "<STR_LIT>" ] <EOL> neutron_scenario . _create_v1_pools = mock . Mock ( return_value = pools ) <EOL> neutron_scenario . _create_v1_vip = mock . Mock ( return_value = vip ) <EOL> neutron_scenario . _delete_v1_vip = mock . Mock ( ) <EOL> neutron_scenario . create_and_delete_vips ( <EOL> pool_create_args = pool_create_args , <EOL> vip_create_args = vip_create_args ) <EOL> neutron_scenario . _create_v1_pools . assert_called_once_with ( <EOL> networks , ** pool_data ) <EOL> neutron_scenario . _create_v1_vip . assert_has_calls ( <EOL> [ mock . call ( pool , ** vip_data ) for pool in pools ] ) <EOL> neutron_scenario . _delete_v1_vip . assert_has_calls ( <EOL> [ mock . call ( vip [ "<STR_LIT>" ] ) ] ) <EOL> @ ddt . data ( <EOL> { } , <EOL> { "<STR_LIT>" : None } , <EOL> { "<STR_LIT>" : { } } , <EOL> { "<STR_LIT>" : { "<STR_LIT:name>" : "<STR_LIT>" } } , <EOL> { "<STR_LIT>" : None } , <EOL> { "<STR_LIT>" : { } } , <EOL> { "<STR_LIT>" : { "<STR_LIT:name>" : "<STR_LIT>" } } , <EOL> ) <EOL> @ ddt . unpack <EOL> def test_create_and_update_vips ( self , pool_create_args = None , <EOL> vip_create_args = None , <EOL> vip_update_args = None ) : <EOL> neutron_scenario = loadbalancer_v1 . NeutronLoadbalancerV1 ( <EOL> self . _get_context ( ) ) <EOL> pools = [ { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:id>" : "<STR_LIT>" , <EOL> } <EOL> } ] <EOL> expected_vip = { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:id>" : "<STR_LIT>" , <EOL> "<STR_LIT:name>" : "<STR_LIT>" <EOL> } <EOL> } <EOL> updated_vip = { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:id>" : "<STR_LIT>" , <EOL> "<STR_LIT:name>" : "<STR_LIT>" <EOL> } <EOL> } <EOL> vips = [ expected_vip ] <EOL> vip_data = vip_create_args or { } <EOL> vip_update_data = vip_update_args or { } <EOL> pool_data = pool_create_args or { } <EOL> networks = self . _get_context ( ) [ "<STR_LIT>" ] [ "<STR_LIT>" ] <EOL> neutron_scenario . _create_v1_pools = mock . Mock ( return_value = pools ) <EOL> neutron_scenario . _create_v1_vip = mock . Mock ( return_value = expected_vip ) <EOL> neutron_scenario . _update_v1_vip = mock . Mock ( return_value = updated_vip ) <EOL> neutron_scenario . create_and_update_vips ( <EOL> pool_create_args = pool_create_args , vip_create_args = vip_create_args , <EOL> vip_update_args = vip_update_args ) <EOL> neutron_scenario . _create_v1_pools . assert_called_once_with ( <EOL> networks , ** pool_data ) <EOL> neutron_scenario . _create_v1_vip . assert_has_calls ( <EOL> [ mock . call ( pool , ** vip_data ) for pool in pools ] ) <EOL> neutron_scenario . _update_v1_vip . assert_has_calls ( <EOL> [ mock . call ( vip , ** vip_update_data ) for vip in vips ] ) <EOL> @ ddt . data ( <EOL> { } , <EOL> { "<STR_LIT>" : None } , <EOL> { "<STR_LIT>" : { } } , <EOL> { "<STR_LIT>" : { "<STR_LIT:name>" : "<STR_LIT>" } } , <EOL> ) <EOL> @ ddt . unpack <EOL> def test_create_and_list_healthmonitors ( self , <EOL> healthmonitor_create_args = None ) : <EOL> neutron_scenario = loadbalancer_v1 . NeutronLoadbalancerV1 ( <EOL> self . _get_context ( ) ) <EOL> hm_data = healthmonitor_create_args or { } <EOL> neutron_scenario . _create_v1_healthmonitor = mock . Mock ( ) <EOL> neutron_scenario . _list_v1_healthmonitors = mock . Mock ( ) <EOL> neutron_scenario . create_and_list_healthmonitors ( <EOL> healthmonitor_create_args = healthmonitor_create_args ) <EOL> neutron_scenario . _create_v1_healthmonitor . assert_called_once_with ( <EOL> ** hm_data ) <EOL> neutron_scenario . _list_v1_healthmonitors . assert_called_once_with ( ) <EOL> @ ddt . data ( <EOL> { } , <EOL> { "<STR_LIT>" : None } , <EOL> { "<STR_LIT>" : { } } , <EOL> { "<STR_LIT>" : { "<STR_LIT:name>" : "<STR_LIT>" } } , <EOL> ) <EOL> @ ddt . unpack <EOL> def test_create_and_delete_healthmonitors ( self , <EOL> healthmonitor_create_args = None ) : <EOL> neutron_scenario = loadbalancer_v1 . NeutronLoadbalancerV1 ( <EOL> self . _get_context ( ) ) <EOL> hm = { "<STR_LIT>" : { "<STR_LIT:id>" : "<STR_LIT>" } } <EOL> hm_data = healthmonitor_create_args or { } <EOL> neutron_scenario . _create_v1_healthmonitor = mock . Mock ( return_value = hm ) <EOL> neutron_scenario . _delete_v1_healthmonitor = mock . Mock ( ) <EOL> neutron_scenario . create_and_delete_healthmonitors ( <EOL> healthmonitor_create_args = healthmonitor_create_args ) <EOL> neutron_scenario . _create_v1_healthmonitor . assert_called_once_with ( <EOL> ** hm_data ) <EOL> neutron_scenario . _delete_v1_healthmonitor . assert_called_once_with ( <EOL> neutron_scenario . _create_v1_healthmonitor . return_value [ <EOL> "<STR_LIT>" ] ) <EOL> @ ddt . data ( <EOL> { } , <EOL> { "<STR_LIT>" : None } , <EOL> { "<STR_LIT>" : { } } , <EOL> { "<STR_LIT>" : { "<STR_LIT:name>" : "<STR_LIT>" } } , <EOL> ) <EOL> @ ddt . unpack <EOL> def test_create_and_update_healthmonitors ( self , <EOL> healthmonitor_create_args = None , <EOL> healthmonitor_update_args = None ) : <EOL> neutron_scenario = loadbalancer_v1 . NeutronLoadbalancerV1 ( <EOL> self . _get_context ( ) ) <EOL> mock_random = loadbalancer_v1 . random = mock . Mock ( ) <EOL> hm = { "<STR_LIT>" : { "<STR_LIT:id>" : "<STR_LIT>" } } <EOL> hm_data = healthmonitor_create_args or { } <EOL> hm_update_data = healthmonitor_update_args or { <EOL> "<STR_LIT>" : mock_random . choice . return_value } <EOL> neutron_scenario . _create_v1_healthmonitor = mock . Mock ( return_value = hm ) <EOL> neutron_scenario . _update_v1_healthmonitor = mock . Mock ( ) <EOL> neutron_scenario . create_and_update_healthmonitors ( <EOL> healthmonitor_create_args = healthmonitor_create_args , <EOL> healthmonitor_update_args = healthmonitor_update_args ) <EOL> neutron_scenario . _create_v1_healthmonitor . assert_called_once_with ( <EOL> ** hm_data ) <EOL> neutron_scenario . _update_v1_healthmonitor . assert_called_once_with ( <EOL> neutron_scenario . _create_v1_healthmonitor . return_value , <EOL> ** hm_update_data ) </s>
