<s> import copy <EOL> import mock <EOL> from webob import exc <EOL> from oslo_utils import uuidutils <EOL> from neutron . tests . unit . api . v2 import test_base <EOL> from neutron . tests . unit . extensions import base as test_ext <EOL> from networking_sfc . extensions import sfc as sfc_ext <EOL> _uuid = uuidutils . generate_uuid <EOL> _get_path = test_base . _get_path <EOL> PORT_CHAIN_PATH = ( sfc_ext . SFC_PREFIX [ <NUM_LIT:1> : ] + '<STR_LIT>' ) <EOL> PORT_PAIR_PATH = ( sfc_ext . SFC_PREFIX [ <NUM_LIT:1> : ] + '<STR_LIT>' ) <EOL> PORT_PAIR_GROUP_PATH = ( sfc_ext . SFC_PREFIX [ <NUM_LIT:1> : ] + '<STR_LIT>' ) <EOL> fmt = '<STR_LIT>' <EOL> class OnosSfcDriverTestCase ( test_ext . ExtensionTestCase ) : <EOL> def setUp ( self ) : <EOL> super ( OnosSfcDriverTestCase , self ) . setUp ( ) <EOL> self . _setUpExtension ( <EOL> '<STR_LIT>' , <EOL> sfc_ext . SFC_EXT , <EOL> sfc_ext . RESOURCE_ATTRIBUTE_MAP , <EOL> sfc_ext . Sfc , <EOL> sfc_ext . SFC_PREFIX [ <NUM_LIT:1> : ] , <EOL> plural_mappings = { } <EOL> ) <EOL> self . instance = self . plugin . return_value <EOL> def _get_expected_port_chain ( self , data ) : <EOL> return { '<STR_LIT>' : { <EOL> '<STR_LIT:description>' : data [ '<STR_LIT>' ] . get ( '<STR_LIT:description>' ) or '<STR_LIT>' , <EOL> '<STR_LIT:name>' : data [ '<STR_LIT>' ] . get ( '<STR_LIT:name>' ) or '<STR_LIT>' , <EOL> '<STR_LIT>' : data [ '<STR_LIT>' ] [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : data [ '<STR_LIT>' ] . get ( <EOL> '<STR_LIT>' ) or { '<STR_LIT>' : '<STR_LIT>' } , <EOL> '<STR_LIT>' : data [ '<STR_LIT>' ] . get ( <EOL> '<STR_LIT>' ) or [ ] , <EOL> '<STR_LIT>' : data [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> } } <EOL> def test_create_port_chain ( self ) : <EOL> portchain_id = _uuid ( ) <EOL> data = { '<STR_LIT>' : { <EOL> '<STR_LIT>' : [ _uuid ( ) ] , <EOL> '<STR_LIT>' : _uuid ( ) <EOL> } } <EOL> expected_data = self . _get_expected_port_chain ( data ) <EOL> return_value = copy . copy ( expected_data [ '<STR_LIT>' ] ) <EOL> return_value . update ( { '<STR_LIT:id>' : portchain_id } ) <EOL> self . instance . create_port_chain . return_value = return_value <EOL> res = self . api . post ( _get_path ( PORT_CHAIN_PATH , fmt = self . fmt ) , <EOL> self . serialize ( data ) , <EOL> content_type = '<STR_LIT>' % self . fmt ) <EOL> self . instance . create_port_chain . assert_called_with ( <EOL> mock . ANY , <EOL> port_chain = expected_data ) <EOL> self . assertEqual ( res . status_int , exc . HTTPCreated . code ) <EOL> res = self . deserialize ( res ) <EOL> self . assertIn ( '<STR_LIT>' , res ) <EOL> self . assertEqual ( return_value , res [ '<STR_LIT>' ] ) <EOL> def test_port_chain_update ( self ) : <EOL> portchain_id = _uuid ( ) <EOL> update_data = { '<STR_LIT>' : { <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT:description>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : [ _uuid ( ) ] <EOL> } } <EOL> return_value = { <EOL> '<STR_LIT>' : _uuid ( ) , <EOL> '<STR_LIT:id>' : portchain_id <EOL> } <EOL> self . instance . update_port_chain . return_value = return_value <EOL> res = self . api . put ( _get_path ( PORT_CHAIN_PATH , id = portchain_id , <EOL> fmt = self . fmt ) , <EOL> self . serialize ( update_data ) ) <EOL> self . instance . update_port_chain . assert_called_with ( <EOL> mock . ANY , portchain_id , <EOL> port_chain = update_data ) <EOL> self . assertEqual ( res . status_int , exc . HTTPOk . code ) <EOL> res = self . deserialize ( res ) <EOL> self . assertIn ( '<STR_LIT>' , res ) <EOL> self . assertEqual ( res [ '<STR_LIT>' ] , return_value ) <EOL> def test_port_chain_delete ( self ) : <EOL> self . _test_entity_delete ( '<STR_LIT>' ) <EOL> def _get_expected_port_pair_group ( self , data ) : <EOL> return { '<STR_LIT>' : { <EOL> '<STR_LIT:description>' : data [ '<STR_LIT>' ] . get ( '<STR_LIT:description>' ) or '<STR_LIT>' , <EOL> '<STR_LIT:name>' : data [ '<STR_LIT>' ] . get ( '<STR_LIT:name>' ) or '<STR_LIT>' , <EOL> '<STR_LIT>' : data [ '<STR_LIT>' ] . get ( '<STR_LIT>' ) or [ ] , <EOL> '<STR_LIT>' : data [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> } } <EOL> def test_create_port_pair_group ( self ) : <EOL> portpairgroup_id = _uuid ( ) <EOL> data = { '<STR_LIT>' : { <EOL> '<STR_LIT>' : _uuid ( ) <EOL> } } <EOL> expected_data = self . _get_expected_port_pair_group ( data ) <EOL> return_value = copy . copy ( expected_data [ '<STR_LIT>' ] ) <EOL> return_value . update ( { '<STR_LIT:id>' : portpairgroup_id } ) <EOL> self . instance . create_port_pair_group . return_value = return_value <EOL> res = self . api . post ( <EOL> _get_path ( PORT_PAIR_GROUP_PATH , fmt = self . fmt ) , <EOL> self . serialize ( data ) , <EOL> content_type = '<STR_LIT>' % self . fmt ) <EOL> self . instance . create_port_pair_group . assert_called_with ( <EOL> mock . ANY , <EOL> port_pair_group = expected_data ) <EOL> self . assertEqual ( res . status_int , exc . HTTPCreated . code ) <EOL> res = self . deserialize ( res ) <EOL> self . assertIn ( '<STR_LIT>' , res ) <EOL> self . assertEqual ( return_value , res [ '<STR_LIT>' ] ) <EOL> def test_port_pair_group_update ( self ) : <EOL> portpairgroup_id = _uuid ( ) <EOL> update_data = { '<STR_LIT>' : { <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT:description>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : [ _uuid ( ) ] <EOL> } } <EOL> return_value = { <EOL> '<STR_LIT>' : _uuid ( ) , <EOL> '<STR_LIT:id>' : portpairgroup_id <EOL> } <EOL> self . instance . update_port_pair_group . return_value = return_value <EOL> res = self . api . put ( <EOL> _get_path ( <EOL> PORT_PAIR_GROUP_PATH , id = portpairgroup_id , <EOL> fmt = self . fmt ) , <EOL> self . serialize ( update_data ) ) <EOL> self . instance . update_port_pair_group . assert_called_with ( <EOL> mock . ANY , portpairgroup_id , <EOL> port_pair_group = update_data ) <EOL> self . assertEqual ( res . status_int , exc . HTTPOk . code ) <EOL> res = self . deserialize ( res ) <EOL> self . assertIn ( '<STR_LIT>' , res ) <EOL> self . assertEqual ( res [ '<STR_LIT>' ] , return_value ) <EOL> def test_port_pair_group_delete ( self ) : <EOL> self . _test_entity_delete ( '<STR_LIT>' ) <EOL> def _get_expected_port_pair ( self , data ) : <EOL> return { '<STR_LIT>' : { <EOL> '<STR_LIT:name>' : data [ '<STR_LIT>' ] . get ( '<STR_LIT:name>' ) or '<STR_LIT>' , <EOL> '<STR_LIT:description>' : data [ '<STR_LIT>' ] . get ( '<STR_LIT:description>' ) or '<STR_LIT>' , <EOL> '<STR_LIT>' : data [ '<STR_LIT>' ] [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : data [ '<STR_LIT>' ] [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : data [ '<STR_LIT>' ] . get ( <EOL> '<STR_LIT>' ) or { '<STR_LIT>' : None } , <EOL> '<STR_LIT>' : data [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> } } <EOL> def test_create_port_pair ( self ) : <EOL> portpair_id = _uuid ( ) <EOL> data = { '<STR_LIT>' : { <EOL> '<STR_LIT>' : _uuid ( ) , <EOL> '<STR_LIT>' : _uuid ( ) , <EOL> '<STR_LIT>' : _uuid ( ) <EOL> } } <EOL> expected_data = self . _get_expected_port_pair ( data ) <EOL> return_value = copy . copy ( expected_data [ '<STR_LIT>' ] ) <EOL> return_value . update ( { '<STR_LIT:id>' : portpair_id } ) <EOL> self . instance . create_port_pair . return_value = return_value <EOL> res = self . api . post ( _get_path ( PORT_PAIR_PATH , fmt = self . fmt ) , <EOL> self . serialize ( data ) , <EOL> content_type = '<STR_LIT>' % self . fmt ) <EOL> self . instance . create_port_pair . assert_called_with ( <EOL> mock . ANY , <EOL> port_pair = expected_data ) <EOL> self . assertEqual ( res . status_int , exc . HTTPCreated . code ) <EOL> res = self . deserialize ( res ) <EOL> self . assertIn ( '<STR_LIT>' , res ) <EOL> self . assertEqual ( return_value , res [ '<STR_LIT>' ] ) <EOL> def test_port_pair_update ( self ) : <EOL> portpair_id = _uuid ( ) <EOL> update_data = { '<STR_LIT>' : { <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT:description>' : '<STR_LIT>' <EOL> } } <EOL> return_value = { <EOL> '<STR_LIT>' : _uuid ( ) , <EOL> '<STR_LIT:id>' : portpair_id <EOL> } <EOL> self . instance . update_port_pair . return_value = return_value <EOL> res = self . api . put ( _get_path ( PORT_PAIR_PATH , id = portpair_id , <EOL> fmt = self . fmt ) , <EOL> self . serialize ( update_data ) ) <EOL> self . instance . update_port_pair . assert_called_with ( <EOL> mock . ANY , portpair_id , <EOL> port_pair = update_data ) <EOL> self . assertEqual ( res . status_int , exc . HTTPOk . code ) <EOL> res = self . deserialize ( res ) <EOL> self . assertIn ( '<STR_LIT>' , res ) <EOL> self . assertEqual ( res [ '<STR_LIT>' ] , return_value ) <EOL> def test_port_pair_delete ( self ) : <EOL> self . _test_entity_delete ( '<STR_LIT>' ) </s>
