<s> from mock import patch , call <EOL> from unittest import TestCase <EOL> from itertools import product <EOL> from json import dumps <EOL> from kamaki . clients import network <EOL> class NetworkRestClient ( TestCase ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> self . url = '<STR_LIT>' <EOL> self . token = '<STR_LIT>' <EOL> self . client = network . NetworkRestClient ( self . url , self . token ) <EOL> def tearDown ( self ) : <EOL> del self . client <EOL> def _assert ( self , method_call , path , set_param = None , params = ( ) , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> x0 = - len ( params ) <EOL> for i , ( k , v , c ) in enumerate ( params ) : <EOL> self . assertEqual ( set_param . mock_calls [ x0 + i ] , call ( k , v , iff = c ) ) <EOL> self . assertEqual ( method_call . mock_calls [ - <NUM_LIT:1> ] , call ( path , ** kwargs ) ) <EOL> @ patch ( '<STR_LIT>' , return_value = '<STR_LIT>' ) <EOL> def test_networks_get ( self , get ) : <EOL> netid = '<STR_LIT>' <EOL> for kwargs in ( dict ( ) , dict ( k1 = '<STR_LIT>' ) , dict ( k2 = '<STR_LIT>' , k3 = '<STR_LIT>' ) ) : <EOL> self . assertEqual ( self . client . networks_get ( ** kwargs ) , '<STR_LIT>' ) <EOL> self . _assert ( get , '<STR_LIT>' , ** kwargs ) <EOL> self . assertEqual ( <EOL> self . client . networks_get ( network_id = netid , ** kwargs ) , <EOL> '<STR_LIT>' ) <EOL> self . _assert ( get , '<STR_LIT>' % netid , ** kwargs ) <EOL> @ patch ( '<STR_LIT>' , return_value = '<STR_LIT>' ) <EOL> def test_networks_post ( self , post ) : <EOL> for kwargs in ( <EOL> dict ( json_data = dict ( k1 = '<STR_LIT>' ) ) , <EOL> dict ( json_data = dict ( k2 = '<STR_LIT>' ) , k3 = '<STR_LIT>' ) ) : <EOL> self . assertEqual ( self . client . networks_post ( ** kwargs ) , '<STR_LIT>' ) <EOL> json_data = kwargs . pop ( '<STR_LIT>' ) <EOL> self . _assert ( post , '<STR_LIT>' , json = json_data , ** kwargs ) <EOL> @ patch ( '<STR_LIT>' , return_value = '<STR_LIT>' ) <EOL> def test_networks_put ( self , put ) : <EOL> netid = '<STR_LIT>' <EOL> for kwargs in ( <EOL> dict ( json_data = dict ( k1 = '<STR_LIT>' ) ) , <EOL> dict ( json_data = dict ( k2 = '<STR_LIT>' ) , k3 = '<STR_LIT>' ) ) : <EOL> self . assertEqual ( <EOL> self . client . networks_put ( netid , ** kwargs ) , '<STR_LIT>' ) <EOL> json_data = kwargs . pop ( '<STR_LIT>' ) <EOL> self . _assert ( <EOL> put , '<STR_LIT>' % netid , json = json_data , ** kwargs ) <EOL> @ patch ( '<STR_LIT>' , return_value = '<STR_LIT>' ) <EOL> def test_networks_delete ( self , delete ) : <EOL> netid = '<STR_LIT>' <EOL> for kwargs in ( dict ( ) , dict ( k1 = '<STR_LIT>' ) , dict ( k2 = '<STR_LIT>' , k3 = '<STR_LIT>' ) ) : <EOL> self . assertEqual ( <EOL> self . client . networks_delete ( netid , ** kwargs ) , '<STR_LIT>' ) <EOL> self . _assert ( delete , '<STR_LIT>' % netid , ** kwargs ) <EOL> @ patch ( '<STR_LIT>' , return_value = '<STR_LIT>' ) <EOL> def test_subnets_get ( self , get ) : <EOL> for kwargs in ( dict ( ) , dict ( k1 = '<STR_LIT>' ) , dict ( k2 = '<STR_LIT>' , k3 = '<STR_LIT>' ) ) : <EOL> self . assertEqual ( self . client . subnets_get ( ** kwargs ) , '<STR_LIT>' ) <EOL> self . _assert ( get , '<STR_LIT>' , ** kwargs ) <EOL> subnet_id = '<STR_LIT>' <EOL> self . assertEqual ( <EOL> self . client . subnets_get ( subnet_id = subnet_id , ** kwargs ) , <EOL> '<STR_LIT>' ) <EOL> self . _assert ( get , '<STR_LIT>' % subnet_id , ** kwargs ) <EOL> @ patch ( '<STR_LIT>' , return_value = '<STR_LIT>' ) <EOL> def test_subnets_post ( self , post ) : <EOL> for kwargs in ( dict ( ) , dict ( k1 = '<STR_LIT>' ) , dict ( k2 = '<STR_LIT>' , k3 = '<STR_LIT>' ) ) : <EOL> json_data = dict ( subnets = '<STR_LIT>' ) <EOL> self . assertEqual ( self . client . subnets_post ( <EOL> json_data = json_data , ** kwargs ) , '<STR_LIT>' ) <EOL> self . _assert ( post , '<STR_LIT>' , json = json_data , ** kwargs ) <EOL> @ patch ( '<STR_LIT>' , return_value = '<STR_LIT>' ) <EOL> def test_subnets_put ( self , put ) : <EOL> subnet_id = '<STR_LIT>' <EOL> for kwargs in ( dict ( ) , dict ( k1 = '<STR_LIT>' ) , dict ( k2 = '<STR_LIT>' , k3 = '<STR_LIT>' ) ) : <EOL> self . assertEqual ( <EOL> self . client . subnets_put ( subnet_id , ** kwargs ) , '<STR_LIT>' ) <EOL> self . _assert ( put , '<STR_LIT>' % subnet_id , ** kwargs ) <EOL> @ patch ( '<STR_LIT>' , return_value = '<STR_LIT>' ) <EOL> def test_subnets_delete ( self , delete ) : <EOL> netid = '<STR_LIT>' <EOL> for kwargs in ( dict ( ) , dict ( k1 = '<STR_LIT>' ) , dict ( k2 = '<STR_LIT>' , k3 = '<STR_LIT>' ) ) : <EOL> self . assertEqual ( <EOL> self . client . subnets_delete ( netid , ** kwargs ) , '<STR_LIT>' ) <EOL> self . _assert ( delete , '<STR_LIT>' % netid , ** kwargs ) <EOL> @ patch ( '<STR_LIT>' , return_value = '<STR_LIT>' ) <EOL> def test_ports_get ( self , get ) : <EOL> for kwargs in ( dict ( ) , dict ( k1 = '<STR_LIT>' ) , dict ( k2 = '<STR_LIT>' , k3 = '<STR_LIT>' ) ) : <EOL> self . assertEqual ( self . client . ports_get ( ** kwargs ) , '<STR_LIT>' ) <EOL> self . _assert ( get , '<STR_LIT>' , ** kwargs ) <EOL> port_id = '<STR_LIT>' <EOL> self . assertEqual ( <EOL> self . client . ports_get ( port_id = port_id , ** kwargs ) , <EOL> '<STR_LIT>' ) <EOL> self . _assert ( get , '<STR_LIT>' % port_id , ** kwargs ) <EOL> @ patch ( '<STR_LIT>' , return_value = '<STR_LIT>' ) <EOL> def test_ports_post ( self , post ) : <EOL> for kwargs in ( dict ( ) , dict ( k1 = '<STR_LIT>' ) , dict ( k2 = '<STR_LIT>' , k3 = '<STR_LIT>' ) ) : <EOL> self . assertEqual ( self . client . ports_post ( ** kwargs ) , '<STR_LIT>' ) <EOL> self . _assert ( post , '<STR_LIT>' , json = None , ** kwargs ) <EOL> json_data = dict ( id = '<STR_LIT>' , other_param = '<STR_LIT>' ) <EOL> self . assertEqual ( <EOL> self . client . ports_post ( json_data = json_data , ** kwargs ) , <EOL> '<STR_LIT>' ) <EOL> self . _assert ( post , '<STR_LIT>' , json = json_data , ** kwargs ) <EOL> @ patch ( '<STR_LIT>' , return_value = '<STR_LIT>' ) <EOL> def test_ports_put ( self , put ) : <EOL> port_id = '<STR_LIT>' <EOL> for kwargs in ( dict ( ) , dict ( k1 = '<STR_LIT>' ) , dict ( k2 = '<STR_LIT>' , k3 = '<STR_LIT>' ) ) : <EOL> self . assertEqual ( <EOL> self . client . ports_put ( port_id , ** kwargs ) , '<STR_LIT>' ) <EOL> self . _assert ( put , '<STR_LIT>' % port_id , json = None , ** kwargs ) <EOL> json_data = dict ( id = '<STR_LIT>' , other_param = '<STR_LIT>' ) <EOL> self . assertEqual ( <EOL> self . client . ports_put ( port_id , json_data = json_data , ** kwargs ) , <EOL> '<STR_LIT>' ) <EOL> self . _assert ( put , '<STR_LIT>' % port_id , json = json_data , ** kwargs ) <EOL> @ patch ( '<STR_LIT>' , return_value = '<STR_LIT>' ) <EOL> def test_floatingips_get ( self , get ) : <EOL> for kwargs in ( dict ( ) , dict ( k1 = '<STR_LIT>' ) , dict ( k2 = '<STR_LIT>' , k3 = '<STR_LIT>' ) ) : <EOL> self . assertEqual ( self . client . floatingips_get ( ** kwargs ) , '<STR_LIT>' ) <EOL> self . _assert ( get , '<STR_LIT>' , ** kwargs ) <EOL> floatingip_id = '<STR_LIT>' <EOL> self . assertEqual ( <EOL> self . client . floatingips_get ( <EOL> floatingip_id = floatingip_id , ** kwargs ) , <EOL> '<STR_LIT>' ) <EOL> self . _assert ( get , '<STR_LIT>' % floatingip_id , ** kwargs ) <EOL> @ patch ( '<STR_LIT>' , return_value = '<STR_LIT>' ) <EOL> def test_floatingips_post ( self , post ) : <EOL> for kwargs in ( dict ( ) , dict ( k1 = '<STR_LIT>' ) , dict ( k2 = '<STR_LIT>' , k3 = '<STR_LIT>' ) ) : <EOL> json_data = dict ( id = '<STR_LIT>' , other_param = '<STR_LIT>' ) <EOL> self . assertEqual ( <EOL> self . client . floatingips_post ( json_data = json_data , ** kwargs ) , <EOL> '<STR_LIT>' ) <EOL> self . _assert ( post , '<STR_LIT>' , json = json_data , ** kwargs ) <EOL> @ patch ( '<STR_LIT>' , return_value = '<STR_LIT>' ) <EOL> def test_floatingips_put ( self , put ) : <EOL> floatingip_id = '<STR_LIT>' <EOL> for kwargs in ( dict ( ) , dict ( k1 = '<STR_LIT>' ) , dict ( k2 = '<STR_LIT>' , k3 = '<STR_LIT>' ) ) : <EOL> json_data = dict ( id = '<STR_LIT>' , other_param = '<STR_LIT>' ) <EOL> self . assertEqual ( <EOL> self . client . floatingips_put ( <EOL> floatingip_id , json_data = json_data , ** kwargs ) , <EOL> '<STR_LIT>' ) <EOL> self . _assert ( <EOL> put , '<STR_LIT>' % floatingip_id , <EOL> json = json_data , ** kwargs ) <EOL> class FakeObject ( object ) : <EOL> json = None <EOL> headers = None <EOL> class NetworkClient ( TestCase ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> self . url = '<STR_LIT>' <EOL> self . token = '<STR_LIT>' <EOL> self . client = network . NetworkClient ( self . url , self . token ) <EOL> def tearDown ( self ) : <EOL> FakeObject . json , FakeObject . headers = None , None <EOL> del self . client <EOL> @ patch ( <EOL> '<STR_LIT>' , <EOL> return_value = FakeObject ( ) ) <EOL> def test_list_networks ( self , networks_get ) : <EOL> FakeObject . json = dict ( networks = '<STR_LIT>' ) <EOL> self . assertEqual ( self . client . list_networks ( ) , '<STR_LIT>' ) <EOL> networks_get . assert_called_once_with ( success = <NUM_LIT:200> ) <EOL> @ patch ( <EOL> '<STR_LIT>' , <EOL> return_value = FakeObject ( ) ) <EOL> def test_create_network ( self , networks_post ) : <EOL> for admin_state_up , shared in product ( ( None , True ) , ( None , True ) ) : <EOL> FakeObject . json = dict ( network = '<STR_LIT>' ) <EOL> name = '<STR_LIT>' <EOL> self . assertEqual ( <EOL> self . client . create_network ( <EOL> name , admin_state_up = admin_state_up , shared = shared ) , <EOL> '<STR_LIT>' ) <EOL> req = dict ( name = name , admin_state_up = bool ( admin_state_up ) ) <EOL> if shared : <EOL> req [ '<STR_LIT>' ] = shared <EOL> expargs = dict ( json_data = dict ( network = req ) , success = <NUM_LIT> ) <EOL> self . assertEqual ( networks_post . mock_calls [ - <NUM_LIT:1> ] , call ( ** expargs ) ) <EOL> @ patch ( <EOL> '<STR_LIT>' , <EOL> return_value = FakeObject ( ) ) <EOL> def test_create_networks ( self , networks_post ) : <EOL> for networks in ( <EOL> None , dict ( name = '<STR_LIT:name>' ) , '<STR_LIT>' , [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] , [ { '<STR_LIT:k>' : '<STR_LIT:v>' } , ] , <EOL> [ dict ( admin_state_up = True , shared = True ) ] , <EOL> [ dict ( name = '<STR_LIT>' , invalid = '<STR_LIT>' ) , ] , <EOL> [ dict ( name = '<STR_LIT>' , shared = True ) , { '<STR_LIT>' : '<STR_LIT>' } ] ) : <EOL> self . assertRaises ( <EOL> ValueError , self . client . create_networks , networks ) <EOL> FakeObject . json = dict ( networks = '<STR_LIT>' ) <EOL> for networks in ( <EOL> [ <EOL> dict ( name = '<STR_LIT>' ) , <EOL> dict ( name = '<STR_LIT>' , admin_state_up = False , shared = True ) ] , <EOL> [ <EOL> dict ( name = '<STR_LIT>' , admin_state_up = True ) , <EOL> dict ( name = '<STR_LIT>' , shared = False ) , <EOL> dict ( name = '<STR_LIT>' ) ] , <EOL> ( dict ( name = '<STR_LIT>' ) , dict ( name = '<STR_LIT>' ) ) ) : <EOL> self . assertEqual ( self . client . create_networks ( networks ) , '<STR_LIT>' ) <EOL> networks = list ( networks ) <EOL> expargs = dict ( json_data = dict ( networks = networks ) , success = <NUM_LIT> ) <EOL> self . assertEqual ( networks_post . mock_calls [ - <NUM_LIT:1> ] , call ( ** expargs ) ) <EOL> @ patch ( <EOL> '<STR_LIT>' , <EOL> return_value = FakeObject ( ) ) <EOL> def test_get_network_details ( self , networks_get ) : <EOL> netid , FakeObject . json = '<STR_LIT>' , dict ( network = '<STR_LIT>' ) <EOL> self . assertEqual ( self . client . get_network_details ( netid ) , '<STR_LIT>' ) <EOL> networks_get . assert_called_once_with ( netid , success = <NUM_LIT:200> ) <EOL> @ patch ( <EOL> '<STR_LIT>' , <EOL> return_value = FakeObject ( ) ) <EOL> def test_update_network ( self , networks_put ) : <EOL> netid , FakeObject . json = '<STR_LIT>' , dict ( network = '<STR_LIT>' ) <EOL> for name , admin_state_up , shared in product ( <EOL> ( '<STR_LIT>' , None ) , ( True , None ) , ( True , None ) ) : <EOL> kwargs = dict ( <EOL> name = name , admin_state_up = admin_state_up , shared = shared ) <EOL> self . assertEqual ( <EOL> self . client . update_network ( netid , ** kwargs ) , '<STR_LIT>' ) <EOL> if name in ( None , ) : <EOL> kwargs . pop ( '<STR_LIT:name>' ) <EOL> if admin_state_up in ( None , ) : <EOL> kwargs . pop ( '<STR_LIT>' ) <EOL> if shared in ( None , ) : <EOL> kwargs . pop ( '<STR_LIT>' ) <EOL> kwargs = dict ( json_data = dict ( network = kwargs ) , success = <NUM_LIT:200> ) <EOL> self . assertEqual ( <EOL> networks_put . mock_calls [ - <NUM_LIT:1> ] , call ( netid , ** kwargs ) ) <EOL> @ patch ( <EOL> '<STR_LIT>' , <EOL> return_value = FakeObject ( ) ) <EOL> def test_delete_network ( self , networks_delete ) : <EOL> netid , FakeObject . headers = '<STR_LIT>' , '<STR_LIT>' <EOL> self . assertEqual ( self . client . delete_network ( netid ) , '<STR_LIT>' ) <EOL> networks_delete . assert_called_once_with ( netid , success = <NUM_LIT> ) <EOL> @ patch ( <EOL> '<STR_LIT>' , <EOL> return_value = FakeObject ( ) ) <EOL> def test_list_subnets ( self , subnets_get ) : <EOL> FakeObject . json = dict ( subnets = '<STR_LIT>' ) <EOL> self . assertEqual ( self . client . list_subnets ( ) , '<STR_LIT>' ) <EOL> subnets_get . assert_called_once_with ( success = <NUM_LIT:200> ) <EOL> @ patch ( <EOL> '<STR_LIT>' , <EOL> return_value = FakeObject ( ) ) <EOL> def test_create_subnet ( self , subnets_post ) : <EOL> for ( <EOL> name , allocation_pools , gateway_ip , <EOL> subnet_id , ipv6 , enable_dhcp ) in product ( <EOL> ( '<STR_LIT:name>' , None ) , ( '<STR_LIT>' , None ) , ( '<STR_LIT>' , None ) , <EOL> ( '<STR_LIT>' , None ) , ( True , None ) , ( True , None ) ) : <EOL> kwargs = dict ( <EOL> name = name , allocation_pools = allocation_pools , <EOL> gateway_ip = gateway_ip , subnet_id = subnet_id , <EOL> ipv6 = ipv6 , enable_dhcp = enable_dhcp ) <EOL> FakeObject . json , network_id , cidr = dict ( subnet = '<STR_LIT>' ) , '<STR_LIT:name>' , '<STR_LIT>' <EOL> self . assertEqual ( <EOL> self . client . create_subnet ( network_id , cidr , ** kwargs ) , '<STR_LIT>' ) <EOL> req = dict ( <EOL> network_id = network_id , cidr = cidr , <EOL> ip_version = <NUM_LIT:6> if kwargs . pop ( '<STR_LIT>' , None ) else <NUM_LIT:4> ) <EOL> for k , v in kwargs . items ( ) : <EOL> if v : <EOL> req [ '<STR_LIT:id>' if k == '<STR_LIT>' else k ] = v <EOL> expargs = dict ( json_data = dict ( subnet = req ) , success = <NUM_LIT> ) <EOL> self . assertEqual ( subnets_post . mock_calls [ - <NUM_LIT:1> ] , call ( ** expargs ) ) <EOL> @ patch ( <EOL> '<STR_LIT>' , <EOL> return_value = FakeObject ( ) ) <EOL> def test_create_subnets ( self , subnets_post ) : <EOL> for subnets in ( <EOL> None , dict ( network_id = '<STR_LIT:name>' ) , '<STR_LIT>' , [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] , [ { '<STR_LIT:k>' : '<STR_LIT:v>' } ] , <EOL> [ dict ( ipv6 = True , enable_dhcp = True ) ] , <EOL> [ dict ( network_id = '<STR_LIT>' , cidr = '<STR_LIT>' , invalid = '<STR_LIT>' ) , ] , <EOL> [ dict ( network_id = '<STR_LIT>' , cidr = '<STR_LIT>' ) , { '<STR_LIT>' : '<STR_LIT>' } ] ) : <EOL> self . assertRaises ( <EOL> ValueError , self . client . create_subnets , subnets ) <EOL> FakeObject . json = dict ( subnets = '<STR_LIT>' ) <EOL> for subnets in ( <EOL> [ <EOL> dict ( network_id = '<STR_LIT>' , cidr = '<STR_LIT>' ) , <EOL> dict ( network_id = '<STR_LIT>' , cidr = '<STR_LIT>' , name = '<STR_LIT:name>' ) ] , <EOL> [ <EOL> dict ( network_id = '<STR_LIT>' , cidr = '<STR_LIT>' , allocation_pools = '<STR_LIT>' ) , <EOL> dict ( network_id = '<STR_LIT>' , cidr = '<STR_LIT>' , gateway_ip = '<STR_LIT>' ) , <EOL> dict ( network_id = '<STR_LIT>' , cidr = '<STR_LIT>' , subnet_id = '<STR_LIT>' ) , <EOL> dict ( network_id = '<STR_LIT>' , cidr = '<STR_LIT>' , ipv6 = True , name = '<STR_LIT>' ) , <EOL> dict ( network_id = '<STR_LIT>' , cidr = '<STR_LIT>' , enable_dhcp = True ) ] , <EOL> ( <EOL> dict ( network_id = '<STR_LIT>' , cidr = '<STR_LIT>' ) , <EOL> dict ( network_id = '<STR_LIT>' , cidr = '<STR_LIT>' ) ) ) : <EOL> self . assertEqual ( self . client . create_subnets ( subnets ) , '<STR_LIT>' ) <EOL> for subnet in subnets : <EOL> subnet [ '<STR_LIT>' ] = <NUM_LIT:6> if subnet . pop ( '<STR_LIT>' , None ) else <NUM_LIT:4> <EOL> if '<STR_LIT>' in subnet : <EOL> subnet [ '<STR_LIT:id>' ] = subnet . pop ( '<STR_LIT>' ) <EOL> subnets = list ( subnets ) <EOL> expargs = dict ( json_data = dict ( subnets = subnets ) , success = <NUM_LIT> ) <EOL> self . assertEqual ( subnets_post . mock_calls [ - <NUM_LIT:1> ] , call ( ** expargs ) ) <EOL> @ patch ( <EOL> '<STR_LIT>' , <EOL> return_value = FakeObject ( ) ) <EOL> def test_get_subnet_details ( self , subnets_get ) : <EOL> subid , FakeObject . json = '<STR_LIT>' , '<STR_LIT>' <EOL> self . assertEqual ( self . client . get_subnet_details ( subid ) , '<STR_LIT>' ) <EOL> subnets_get . assert_called_once_with ( subid , success = <NUM_LIT:200> ) <EOL> @ patch ( <EOL> '<STR_LIT>' , <EOL> return_value = FakeObject ( ) ) <EOL> def test_update_subnet ( self , subnets_put ) : <EOL> for ( <EOL> name , allocation_pools , gateway_ip , <EOL> ipv6 , enable_dhcp ) in product ( <EOL> ( '<STR_LIT:name>' , None ) , ( '<STR_LIT>' , None ) , ( '<STR_LIT>' , None ) , <EOL> ( True , False , None ) , ( True , False , None ) ) : <EOL> kwargs = dict ( <EOL> name = name , allocation_pools = allocation_pools , <EOL> gateway_ip = gateway_ip , ipv6 = ipv6 , enable_dhcp = enable_dhcp ) <EOL> FakeObject . json , subnet_id = dict ( subnet = '<STR_LIT>' ) , '<STR_LIT>' <EOL> self . assertEqual ( <EOL> self . client . update_subnet ( subnet_id , ** kwargs ) , '<STR_LIT>' ) <EOL> req = dict ( ) <EOL> for k , v in kwargs . items ( ) : <EOL> if v not in ( None , ) : <EOL> if k in ( '<STR_LIT>' , ) : <EOL> req [ '<STR_LIT>' ] = <NUM_LIT:6> if v else <NUM_LIT:4> <EOL> else : <EOL> req [ k ] = v <EOL> expargs = dict ( json = dict ( subnet = req ) , success = <NUM_LIT:200> ) <EOL> self . assertEqual ( <EOL> subnets_put . mock_calls [ - <NUM_LIT:1> ] , call ( subnet_id , ** expargs ) ) <EOL> @ patch ( <EOL> '<STR_LIT>' , <EOL> return_value = FakeObject ( ) ) <EOL> def test_delete_subnet ( self , subnets_delete ) : <EOL> netid , FakeObject . headers = '<STR_LIT>' , '<STR_LIT>' <EOL> self . assertEqual ( self . client . delete_subnet ( netid ) , '<STR_LIT>' ) <EOL> subnets_delete . assert_called_once_with ( netid , success = <NUM_LIT> ) <EOL> @ patch ( <EOL> '<STR_LIT>' , <EOL> return_value = FakeObject ( ) ) <EOL> def test_list_ports ( self , ports_get ) : <EOL> FakeObject . json = dict ( ports = '<STR_LIT>' ) <EOL> self . assertEqual ( self . client . list_ports ( ) , '<STR_LIT>' ) <EOL> ports_get . assert_called_once_with ( success = <NUM_LIT:200> ) <EOL> @ patch ( <EOL> '<STR_LIT>' , <EOL> return_value = FakeObject ( ) ) <EOL> def test_create_port ( self , ports_post ) : <EOL> for ( <EOL> name , status , admin_state_up , <EOL> mac_address , fixed_ips , security_groups <EOL> ) in product ( <EOL> ( '<STR_LIT:name>' , None ) , ( '<STR_LIT:status>' , None ) , ( True , False , None ) , <EOL> ( '<STR_LIT>' , None ) , ( '<STR_LIT>' , None ) , ( [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] , None ) ) : <EOL> kwargs = dict ( <EOL> name = name , status = status , admin_state_up = admin_state_up , <EOL> mac_address = mac_address , fixed_ips = fixed_ips , <EOL> security_groups = security_groups ) <EOL> FakeObject . json , network_id = dict ( port = '<STR_LIT>' ) , '<STR_LIT:name>' <EOL> self . assertEqual ( <EOL> self . client . create_port ( network_id , ** kwargs ) , '<STR_LIT>' ) <EOL> req = dict ( network_id = network_id ) <EOL> for k , v in kwargs . items ( ) : <EOL> if v not in ( None , ) : <EOL> req [ k ] = v <EOL> expargs = dict ( json_data = dict ( port = req ) , success = <NUM_LIT> ) <EOL> self . assertEqual ( ports_post . mock_calls [ - <NUM_LIT:1> ] , call ( ** expargs ) ) <EOL> @ patch ( <EOL> '<STR_LIT>' , <EOL> return_value = FakeObject ( ) ) <EOL> def test_create_ports ( self , ports_post ) : <EOL> for ports in ( <EOL> None , dict ( network_id = '<STR_LIT:name>' ) , '<STR_LIT>' , [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] , [ { '<STR_LIT:k>' : '<STR_LIT:v>' } ] , <EOL> [ dict ( name = True , mac_address = '<STR_LIT>' ) ] , <EOL> [ dict ( network_id = '<STR_LIT>' , invalid = '<STR_LIT>' ) , ] , <EOL> [ dict ( network_id = '<STR_LIT>' , name = '<STR_LIT>' ) , { '<STR_LIT>' : '<STR_LIT>' } ] ) : <EOL> self . assertRaises ( <EOL> ValueError , self . client . create_ports , ports ) <EOL> FakeObject . json = dict ( ports = '<STR_LIT>' ) <EOL> for ports in ( <EOL> [ dict ( network_id = '<STR_LIT>' ) , dict ( network_id = '<STR_LIT>' , name = '<STR_LIT:name>' ) ] , <EOL> [ <EOL> dict ( network_id = '<STR_LIT>' , name = '<STR_LIT>' , status = '<STR_LIT:status>' ) , <EOL> dict ( network_id = '<STR_LIT>' , admin_state_up = True , fixed_ips = '<STR_LIT:f>' ) , <EOL> dict ( network_id = '<STR_LIT>' , mac_address = '<STR_LIT>' , name = '<STR_LIT>' ) , <EOL> dict ( network_id = '<STR_LIT>' , security_groups = '<STR_LIT>' , name = '<STR_LIT>' ) , <EOL> dict ( network_id = '<STR_LIT>' , admin_state_up = False , name = '<STR_LIT>' ) ] , <EOL> ( <EOL> dict ( network_id = '<STR_LIT>' , name = '<STR_LIT>' ) , <EOL> dict ( network_id = '<STR_LIT>' , status = '<STR_LIT>' ) ) ) : <EOL> self . assertEqual ( self . client . create_ports ( ports ) , '<STR_LIT>' ) <EOL> expargs = dict ( json_data = dict ( ports = list ( ports ) ) , success = <NUM_LIT> ) <EOL> self . assertEqual ( ports_post . mock_calls [ - <NUM_LIT:1> ] , call ( ** expargs ) ) <EOL> @ patch ( <EOL> '<STR_LIT>' , <EOL> return_value = FakeObject ( ) ) <EOL> def test_get_port_details ( self , ports_get ) : <EOL> portid , FakeObject . json = '<STR_LIT>' , dict ( port = '<STR_LIT>' ) <EOL> self . assertEqual ( self . client . get_port_details ( portid ) , '<STR_LIT>' ) <EOL> ports_get . assert_called_once_with ( portid , success = <NUM_LIT:200> ) <EOL> @ patch ( <EOL> '<STR_LIT>' , <EOL> return_value = FakeObject ( ) ) <EOL> def test_delete_port ( self , ports_delete ) : <EOL> portid , FakeObject . headers = '<STR_LIT>' , '<STR_LIT>' <EOL> self . assertEqual ( self . client . delete_port ( portid ) , '<STR_LIT>' ) <EOL> ports_delete . assert_called_once_with ( portid , success = <NUM_LIT> ) <EOL> @ patch ( <EOL> '<STR_LIT>' , <EOL> return_value = FakeObject ( ) ) <EOL> def test_update_port ( self , ports_put ) : <EOL> for ( <EOL> name , status , admin_state_up , mac_address , fixed_ips , <EOL> security_groups ) in product ( <EOL> ( '<STR_LIT:name>' , None ) , ( '<STR_LIT>' , None ) , ( True , None ) , ( '<STR_LIT>' , None ) , <EOL> ( '<STR_LIT>' , None ) , ( '<STR_LIT>' , None ) ) : <EOL> FakeObject . json = dict ( port = '<STR_LIT>' ) <EOL> port_id , network_id = '<STR_LIT>' , '<STR_LIT>' <EOL> kwargs = dict ( <EOL> network_id = network_id , name = name , status = status , <EOL> admin_state_up = admin_state_up , mac_address = mac_address , <EOL> fixed_ips = fixed_ips , security_groups = security_groups ) <EOL> self . assertEqual ( <EOL> self . client . update_port ( port_id , ** kwargs ) , '<STR_LIT>' ) <EOL> req = dict ( ) <EOL> for k , v in kwargs . items ( ) : <EOL> if v : <EOL> req [ k ] = v <EOL> expargs = dict ( json_data = dict ( port = req ) , success = <NUM_LIT:200> ) <EOL> self . assertEqual ( <EOL> ports_put . mock_calls [ - <NUM_LIT:1> ] , call ( port_id , ** expargs ) ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> from sys import argv <EOL> from kamaki . clients . test import runTestCase <EOL> not_found = True <EOL> if not argv [ <NUM_LIT:1> : ] or argv [ <NUM_LIT:1> ] == '<STR_LIT>' : <EOL> not_found = False <EOL> runTestCase ( NetworkClient , '<STR_LIT>' , argv [ <NUM_LIT:2> : ] ) <EOL> if not argv [ <NUM_LIT:1> : ] or argv [ <NUM_LIT:1> ] == '<STR_LIT>' : <EOL> not_found = False <EOL> runTestCase ( NetworkRestClient , '<STR_LIT>' , argv [ <NUM_LIT:2> : ] ) <EOL> if not_found : <EOL> print ( '<STR_LIT>' % argv [ <NUM_LIT:1> ] ) </s>
