<s> """<STR_LIT>""" <EOL> from mock import patch <EOL> import os_client_config <EOL> from shade import OpenStackCloud <EOL> from shade . exc import OpenStackCloudException <EOL> from shade . tests . unit import base <EOL> class TestPort ( base . TestCase ) : <EOL> mock_neutron_port_create_rep = { <EOL> '<STR_LIT:port>' : { <EOL> '<STR_LIT:status>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : [ ] , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : { } , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : { } , <EOL> '<STR_LIT>' : [ <EOL> { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> ] , <EOL> '<STR_LIT:id>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : [ ] , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> } <EOL> mock_neutron_port_update_rep = { <EOL> '<STR_LIT:port>' : { <EOL> '<STR_LIT:status>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : [ ] , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : { } , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : { } , <EOL> '<STR_LIT>' : [ <EOL> { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> ] , <EOL> '<STR_LIT:id>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : [ ] , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> } <EOL> mock_neutron_port_list_rep = { <EOL> '<STR_LIT>' : [ <EOL> { <EOL> '<STR_LIT:status>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : [ ] , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : [ ] , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : True <EOL> } , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : { } , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : [ <EOL> { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> ] , <EOL> '<STR_LIT:id>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : [ ] , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } , <EOL> { <EOL> '<STR_LIT:status>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : [ ] , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : [ ] , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : True <EOL> } , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : { } , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : [ <EOL> { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> ] , <EOL> '<STR_LIT:id>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : [ ] , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> ] <EOL> } <EOL> def setUp ( self ) : <EOL> super ( TestPort , self ) . setUp ( ) <EOL> config = os_client_config . OpenStackConfig ( ) <EOL> self . client = OpenStackCloud ( <EOL> cloud_config = config . get_one_cloud ( validate = False ) ) <EOL> @ patch . object ( OpenStackCloud , '<STR_LIT>' ) <EOL> def test_create_port ( self , mock_neutron_client ) : <EOL> mock_neutron_client . create_port . return_value = self . mock_neutron_port_create_rep <EOL> port = self . client . create_port ( <EOL> network_id = '<STR_LIT>' , name = '<STR_LIT>' , <EOL> admin_state_up = True ) <EOL> mock_neutron_client . create_port . assert_called_with ( <EOL> body = { '<STR_LIT:port>' : dict ( network_id = '<STR_LIT>' , name = '<STR_LIT>' , <EOL> admin_state_up = True ) } ) <EOL> self . assertEqual ( self . mock_neutron_port_create_rep [ '<STR_LIT:port>' ] , port ) <EOL> def test_create_port_parameters ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertRaises ( <EOL> TypeError , self . client . create_port , <EOL> network_id = '<STR_LIT>' , nome = '<STR_LIT>' , <EOL> stato_amministrativo_porta = True ) <EOL> @ patch . object ( OpenStackCloud , '<STR_LIT>' ) <EOL> def test_create_port_exception ( self , mock_neutron_client ) : <EOL> mock_neutron_client . create_port . side_effect = Exception ( '<STR_LIT>' ) <EOL> self . assertRaises ( <EOL> OpenStackCloudException , self . client . create_port , <EOL> network_id = '<STR_LIT>' , name = '<STR_LIT>' , <EOL> admin_state_up = True ) <EOL> @ patch . object ( OpenStackCloud , '<STR_LIT>' ) <EOL> def test_update_port ( self , mock_neutron_client ) : <EOL> mock_neutron_client . list_ports . return_value = self . mock_neutron_port_list_rep <EOL> mock_neutron_client . update_port . return_value = self . mock_neutron_port_update_rep <EOL> port = self . client . update_port ( <EOL> name_or_id = '<STR_LIT>' , <EOL> name = '<STR_LIT>' ) <EOL> mock_neutron_client . update_port . assert_called_with ( <EOL> port = '<STR_LIT>' , <EOL> body = { '<STR_LIT:port>' : dict ( name = '<STR_LIT>' ) } ) <EOL> self . assertEqual ( self . mock_neutron_port_update_rep [ '<STR_LIT:port>' ] , port ) <EOL> def test_update_port_parameters ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertRaises ( <EOL> TypeError , self . client . update_port , <EOL> name_or_id = '<STR_LIT>' , nome = '<STR_LIT>' ) <EOL> @ patch . object ( OpenStackCloud , '<STR_LIT>' ) <EOL> def test_update_port_exception ( self , mock_neutron_client ) : <EOL> mock_neutron_client . list_ports . return_value = self . mock_neutron_port_list_rep <EOL> mock_neutron_client . update_port . side_effect = Exception ( '<STR_LIT>' ) <EOL> self . assertRaises ( <EOL> OpenStackCloudException , self . client . update_port , <EOL> name_or_id = '<STR_LIT>' , <EOL> name = '<STR_LIT>' ) <EOL> @ patch . object ( OpenStackCloud , '<STR_LIT>' ) <EOL> def test_list_ports ( self , mock_neutron_client ) : <EOL> mock_neutron_client . list_ports . return_value = self . mock_neutron_port_list_rep <EOL> ports = self . client . list_ports ( ) <EOL> mock_neutron_client . list_ports . assert_called_with ( ) <EOL> self . assertItemsEqual ( self . mock_neutron_port_list_rep [ '<STR_LIT>' ] , ports ) <EOL> @ patch . object ( OpenStackCloud , '<STR_LIT>' ) <EOL> def test_list_ports_exception ( self , mock_neutron_client ) : <EOL> mock_neutron_client . list_ports . side_effect = Exception ( '<STR_LIT>' ) <EOL> self . assertRaises ( OpenStackCloudException , self . client . list_ports ) <EOL> @ patch . object ( OpenStackCloud , '<STR_LIT>' ) <EOL> def test_search_ports_by_id ( self , mock_neutron_client ) : <EOL> mock_neutron_client . list_ports . return_value = self . mock_neutron_port_list_rep <EOL> ports = self . client . search_ports ( <EOL> name_or_id = '<STR_LIT>' ) <EOL> mock_neutron_client . list_ports . assert_called_with ( ) <EOL> self . assertEquals ( <NUM_LIT:1> , len ( ports ) ) <EOL> self . assertEquals ( '<STR_LIT>' , ports [ <NUM_LIT:0> ] [ '<STR_LIT>' ] ) <EOL> @ patch . object ( OpenStackCloud , '<STR_LIT>' ) <EOL> def test_search_ports_by_name ( self , mock_neutron_client ) : <EOL> mock_neutron_client . list_ports . return_value = self . mock_neutron_port_list_rep <EOL> ports = self . client . search_ports ( name_or_id = '<STR_LIT>' ) <EOL> mock_neutron_client . list_ports . assert_called_with ( ) <EOL> self . assertEquals ( <NUM_LIT:1> , len ( ports ) ) <EOL> self . assertEquals ( '<STR_LIT>' , ports [ <NUM_LIT:0> ] [ '<STR_LIT>' ] ) <EOL> @ patch . object ( OpenStackCloud , '<STR_LIT>' ) <EOL> def test_search_ports_not_found ( self , mock_neutron_client ) : <EOL> mock_neutron_client . list_ports . return_value = self . mock_neutron_port_list_rep <EOL> ports = self . client . search_ports ( name_or_id = '<STR_LIT>' ) <EOL> mock_neutron_client . list_ports . assert_called_with ( ) <EOL> self . assertEquals ( <NUM_LIT:0> , len ( ports ) ) <EOL> @ patch . object ( OpenStackCloud , '<STR_LIT>' ) <EOL> def test_delete_port ( self , mock_neutron_client ) : <EOL> mock_neutron_client . list_ports . return_value = self . mock_neutron_port_list_rep <EOL> self . client . delete_port ( name_or_id = '<STR_LIT>' ) <EOL> mock_neutron_client . delete_port . assert_called_with ( <EOL> port = '<STR_LIT>' ) </s>
