<s> import copy <EOL> import mock <EOL> from openstackclient . common import exceptions <EOL> from openstackclient . identity . v3 import mapping <EOL> from openstackclient . tests import fakes <EOL> from openstackclient . tests . identity . v3 import fakes as identity_fakes <EOL> class TestMapping ( identity_fakes . TestFederatedIdentity ) : <EOL> def setUp ( self ) : <EOL> super ( TestMapping , self ) . setUp ( ) <EOL> federation_lib = self . app . client_manager . identity . federation <EOL> self . mapping_mock = federation_lib . mappings <EOL> self . mapping_mock . reset_mock ( ) <EOL> class TestMappingCreate ( TestMapping ) : <EOL> def setUp ( self ) : <EOL> super ( TestMappingCreate , self ) . setUp ( ) <EOL> self . mapping_mock . create . return_value = fakes . FakeResource ( <EOL> None , <EOL> copy . deepcopy ( identity_fakes . MAPPING_RESPONSE ) , <EOL> loaded = True <EOL> ) <EOL> self . cmd = mapping . CreateMapping ( self . app , None ) <EOL> def test_create_mapping ( self ) : <EOL> arglist = [ <EOL> '<STR_LIT>' , identity_fakes . mapping_rules_file_path , <EOL> identity_fakes . mapping_id <EOL> ] <EOL> verifylist = [ <EOL> ( '<STR_LIT>' , identity_fakes . mapping_id ) , <EOL> ( '<STR_LIT>' , identity_fakes . mapping_rules_file_path ) <EOL> ] <EOL> parsed_args = self . check_parser ( self . cmd , arglist , verifylist ) <EOL> mocker = mock . Mock ( ) <EOL> mocker . return_value = identity_fakes . MAPPING_RULES <EOL> with mock . patch ( "<STR_LIT>" <EOL> "<STR_LIT>" , mocker ) : <EOL> columns , data = self . cmd . take_action ( parsed_args ) <EOL> self . mapping_mock . create . assert_called_with ( <EOL> mapping_id = identity_fakes . mapping_id , <EOL> rules = identity_fakes . MAPPING_RULES ) <EOL> collist = ( '<STR_LIT:id>' , '<STR_LIT>' ) <EOL> self . assertEqual ( collist , columns ) <EOL> datalist = ( identity_fakes . mapping_id , <EOL> identity_fakes . MAPPING_RULES ) <EOL> self . assertEqual ( datalist , data ) <EOL> class TestMappingDelete ( TestMapping ) : <EOL> def setUp ( self ) : <EOL> super ( TestMappingDelete , self ) . setUp ( ) <EOL> self . mapping_mock . get . return_value = fakes . FakeResource ( <EOL> None , <EOL> copy . deepcopy ( identity_fakes . MAPPING_RESPONSE ) , <EOL> loaded = True ) <EOL> self . mapping_mock . delete . return_value = None <EOL> self . cmd = mapping . DeleteMapping ( self . app , None ) <EOL> def test_delete_mapping ( self ) : <EOL> arglist = [ <EOL> identity_fakes . mapping_id <EOL> ] <EOL> verifylist = [ <EOL> ( '<STR_LIT>' , identity_fakes . mapping_id ) <EOL> ] <EOL> parsed_args = self . check_parser ( self . cmd , arglist , verifylist ) <EOL> result = self . cmd . take_action ( parsed_args ) <EOL> self . mapping_mock . delete . assert_called_with ( <EOL> identity_fakes . mapping_id ) <EOL> self . assertIsNone ( result ) <EOL> class TestMappingList ( TestMapping ) : <EOL> def setUp ( self ) : <EOL> super ( TestMappingList , self ) . setUp ( ) <EOL> self . mapping_mock . get . return_value = fakes . FakeResource ( <EOL> None , <EOL> { '<STR_LIT:id>' : identity_fakes . mapping_id } , <EOL> loaded = True ) <EOL> self . mapping_mock . list . return_value = [ <EOL> fakes . FakeResource ( <EOL> None , <EOL> { '<STR_LIT:id>' : identity_fakes . mapping_id } , <EOL> loaded = True , <EOL> ) , <EOL> fakes . FakeResource ( <EOL> None , <EOL> { '<STR_LIT:id>' : '<STR_LIT>' } , <EOL> loaded = True , <EOL> ) , <EOL> ] <EOL> self . cmd = mapping . ListMapping ( self . app , None ) <EOL> def test_mapping_list ( self ) : <EOL> arglist = [ ] <EOL> verifylist = [ ] <EOL> parsed_args = self . check_parser ( self . cmd , arglist , verifylist ) <EOL> columns , data = self . cmd . take_action ( parsed_args ) <EOL> self . mapping_mock . list . assert_called_with ( ) <EOL> collist = ( '<STR_LIT>' , ) <EOL> self . assertEqual ( collist , columns ) <EOL> datalist = [ ( identity_fakes . mapping_id , ) , ( '<STR_LIT>' , ) ] <EOL> self . assertEqual ( datalist , data ) <EOL> class TestMappingSet ( TestMapping ) : <EOL> def setUp ( self ) : <EOL> super ( TestMappingSet , self ) . setUp ( ) <EOL> self . mapping_mock . get . return_value = fakes . FakeResource ( <EOL> None , <EOL> copy . deepcopy ( identity_fakes . MAPPING_RESPONSE ) , <EOL> loaded = True <EOL> ) <EOL> self . mapping_mock . update . return_value = fakes . FakeResource ( <EOL> None , <EOL> identity_fakes . MAPPING_RESPONSE_2 , <EOL> loaded = True <EOL> ) <EOL> self . cmd = mapping . SetMapping ( self . app , None ) <EOL> def test_set_new_rules ( self ) : <EOL> arglist = [ <EOL> '<STR_LIT>' , identity_fakes . mapping_rules_file_path , <EOL> identity_fakes . mapping_id <EOL> ] <EOL> verifylist = [ <EOL> ( '<STR_LIT>' , identity_fakes . mapping_id ) , <EOL> ( '<STR_LIT>' , identity_fakes . mapping_rules_file_path ) <EOL> ] <EOL> parsed_args = self . check_parser ( self . cmd , arglist , verifylist ) <EOL> mocker = mock . Mock ( ) <EOL> mocker . return_value = identity_fakes . MAPPING_RULES_2 <EOL> with mock . patch ( "<STR_LIT>" <EOL> "<STR_LIT>" , mocker ) : <EOL> columns , data = self . cmd . take_action ( parsed_args ) <EOL> self . mapping_mock . update . assert_called_with ( <EOL> mapping = identity_fakes . mapping_id , <EOL> rules = identity_fakes . MAPPING_RULES_2 ) <EOL> collist = ( '<STR_LIT:id>' , '<STR_LIT>' ) <EOL> self . assertEqual ( collist , columns ) <EOL> datalist = ( identity_fakes . mapping_id , <EOL> identity_fakes . MAPPING_RULES_2 ) <EOL> self . assertEqual ( datalist , data ) <EOL> def test_set_rules_wrong_file_path ( self ) : <EOL> arglist = [ <EOL> '<STR_LIT>' , identity_fakes . mapping_rules_file_path , <EOL> identity_fakes . mapping_id <EOL> ] <EOL> verifylist = [ <EOL> ( '<STR_LIT>' , identity_fakes . mapping_id ) , <EOL> ( '<STR_LIT>' , identity_fakes . mapping_rules_file_path ) <EOL> ] <EOL> parsed_args = self . check_parser ( self . cmd , arglist , verifylist ) <EOL> self . assertRaises ( <EOL> exceptions . CommandError , <EOL> self . cmd . take_action , <EOL> parsed_args ) <EOL> class TestMappingShow ( TestMapping ) : <EOL> def setUp ( self ) : <EOL> super ( TestMappingShow , self ) . setUp ( ) <EOL> self . mapping_mock . get . return_value = fakes . FakeResource ( <EOL> None , <EOL> copy . deepcopy ( identity_fakes . MAPPING_RESPONSE ) , <EOL> loaded = True <EOL> ) <EOL> self . cmd = mapping . ShowMapping ( self . app , None ) <EOL> def test_mapping_show ( self ) : <EOL> arglist = [ <EOL> identity_fakes . mapping_id <EOL> ] <EOL> verifylist = [ <EOL> ( '<STR_LIT>' , identity_fakes . mapping_id ) <EOL> ] <EOL> parsed_args = self . check_parser ( self . cmd , arglist , verifylist ) <EOL> columns , data = self . cmd . take_action ( parsed_args ) <EOL> self . mapping_mock . get . assert_called_with ( <EOL> identity_fakes . mapping_id ) <EOL> collist = ( '<STR_LIT:id>' , '<STR_LIT>' ) <EOL> self . assertEqual ( collist , columns ) <EOL> datalist = ( identity_fakes . mapping_id , <EOL> identity_fakes . MAPPING_RULES ) <EOL> self . assertEqual ( datalist , data ) </s>
