<s> import copy <EOL> import mock <EOL> from openstackclient . identity . v3 import identity_provider <EOL> from openstackclient . tests import fakes <EOL> from openstackclient . tests . identity . v3 import fakes as identity_fakes <EOL> class TestIdentityProvider ( identity_fakes . TestFederatedIdentity ) : <EOL> def setUp ( self ) : <EOL> super ( TestIdentityProvider , self ) . setUp ( ) <EOL> federation_lib = self . app . client_manager . identity . federation <EOL> self . identity_providers_mock = federation_lib . identity_providers <EOL> self . identity_providers_mock . reset_mock ( ) <EOL> class TestIdentityProviderCreate ( TestIdentityProvider ) : <EOL> columns = ( <EOL> '<STR_LIT:description>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT:id>' , <EOL> '<STR_LIT>' , <EOL> ) <EOL> datalist = ( <EOL> identity_fakes . idp_description , <EOL> True , <EOL> identity_fakes . idp_id , <EOL> identity_fakes . formatted_idp_remote_ids , <EOL> ) <EOL> def setUp ( self ) : <EOL> super ( TestIdentityProviderCreate , self ) . setUp ( ) <EOL> copied_idp = copy . deepcopy ( identity_fakes . IDENTITY_PROVIDER ) <EOL> resource = fakes . FakeResource ( None , copied_idp , loaded = True ) <EOL> self . identity_providers_mock . create . return_value = resource <EOL> self . cmd = identity_provider . CreateIdentityProvider ( self . app , None ) <EOL> def test_create_identity_provider_no_options ( self ) : <EOL> arglist = [ <EOL> identity_fakes . idp_id , <EOL> ] <EOL> verifylist = [ <EOL> ( '<STR_LIT>' , identity_fakes . idp_id ) , <EOL> ] <EOL> parsed_args = self . check_parser ( self . cmd , arglist , verifylist ) <EOL> columns , data = self . cmd . take_action ( parsed_args ) <EOL> kwargs = { <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT:description>' : None , <EOL> } <EOL> self . identity_providers_mock . create . assert_called_with ( <EOL> id = identity_fakes . idp_id , <EOL> ** kwargs <EOL> ) <EOL> self . assertEqual ( self . columns , columns ) <EOL> self . assertEqual ( self . datalist , data ) <EOL> def test_create_identity_provider_description ( self ) : <EOL> arglist = [ <EOL> '<STR_LIT>' , identity_fakes . idp_description , <EOL> identity_fakes . idp_id , <EOL> ] <EOL> verifylist = [ <EOL> ( '<STR_LIT>' , identity_fakes . idp_id ) , <EOL> ( '<STR_LIT:description>' , identity_fakes . idp_description ) , <EOL> ] <EOL> parsed_args = self . check_parser ( self . cmd , arglist , verifylist ) <EOL> columns , data = self . cmd . take_action ( parsed_args ) <EOL> kwargs = { <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT:description>' : identity_fakes . idp_description , <EOL> '<STR_LIT>' : True , <EOL> } <EOL> self . identity_providers_mock . create . assert_called_with ( <EOL> id = identity_fakes . idp_id , <EOL> ** kwargs <EOL> ) <EOL> self . assertEqual ( self . columns , columns ) <EOL> self . assertEqual ( self . datalist , data ) <EOL> def test_create_identity_provider_remote_id ( self ) : <EOL> arglist = [ <EOL> identity_fakes . idp_id , <EOL> '<STR_LIT>' , identity_fakes . idp_remote_ids [ <NUM_LIT:0> ] <EOL> ] <EOL> verifylist = [ <EOL> ( '<STR_LIT>' , identity_fakes . idp_id ) , <EOL> ( '<STR_LIT>' , identity_fakes . idp_remote_ids [ : <NUM_LIT:1> ] ) , <EOL> ] <EOL> parsed_args = self . check_parser ( self . cmd , arglist , verifylist ) <EOL> columns , data = self . cmd . take_action ( parsed_args ) <EOL> kwargs = { <EOL> '<STR_LIT>' : identity_fakes . idp_remote_ids [ : <NUM_LIT:1> ] , <EOL> '<STR_LIT:description>' : None , <EOL> '<STR_LIT>' : True , <EOL> } <EOL> self . identity_providers_mock . create . assert_called_with ( <EOL> id = identity_fakes . idp_id , <EOL> ** kwargs <EOL> ) <EOL> self . assertEqual ( self . columns , columns ) <EOL> self . assertEqual ( self . datalist , data ) <EOL> def test_create_identity_provider_remote_ids_multiple ( self ) : <EOL> arglist = [ <EOL> '<STR_LIT>' , identity_fakes . idp_remote_ids [ <NUM_LIT:0> ] , <EOL> '<STR_LIT>' , identity_fakes . idp_remote_ids [ <NUM_LIT:1> ] , <EOL> identity_fakes . idp_id <EOL> ] <EOL> verifylist = [ <EOL> ( '<STR_LIT>' , identity_fakes . idp_id ) , <EOL> ( '<STR_LIT>' , identity_fakes . idp_remote_ids ) , <EOL> ] <EOL> parsed_args = self . check_parser ( self . cmd , arglist , verifylist ) <EOL> columns , data = self . cmd . take_action ( parsed_args ) <EOL> kwargs = { <EOL> '<STR_LIT>' : identity_fakes . idp_remote_ids , <EOL> '<STR_LIT:description>' : None , <EOL> '<STR_LIT>' : True , <EOL> } <EOL> self . identity_providers_mock . create . assert_called_with ( <EOL> id = identity_fakes . idp_id , <EOL> ** kwargs <EOL> ) <EOL> self . assertEqual ( self . columns , columns ) <EOL> self . assertEqual ( self . datalist , data ) <EOL> def test_create_identity_provider_remote_ids_file ( self ) : <EOL> arglist = [ <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> identity_fakes . idp_id , <EOL> ] <EOL> verifylist = [ <EOL> ( '<STR_LIT>' , identity_fakes . idp_id ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ] <EOL> parsed_args = self . check_parser ( self . cmd , arglist , verifylist ) <EOL> mocker = mock . Mock ( ) <EOL> mocker . return_value = "<STR_LIT:\n>" . join ( identity_fakes . idp_remote_ids ) <EOL> with mock . patch ( "<STR_LIT>" <EOL> "<STR_LIT>" , mocker ) : <EOL> columns , data = self . cmd . take_action ( parsed_args ) <EOL> kwargs = { <EOL> '<STR_LIT>' : identity_fakes . idp_remote_ids , <EOL> '<STR_LIT:description>' : None , <EOL> '<STR_LIT>' : True , <EOL> } <EOL> self . identity_providers_mock . create . assert_called_with ( <EOL> id = identity_fakes . idp_id , <EOL> ** kwargs <EOL> ) <EOL> self . assertEqual ( self . columns , columns ) <EOL> self . assertEqual ( self . datalist , data ) <EOL> def test_create_identity_provider_disabled ( self ) : <EOL> IDENTITY_PROVIDER = copy . deepcopy ( identity_fakes . IDENTITY_PROVIDER ) <EOL> IDENTITY_PROVIDER [ '<STR_LIT>' ] = False <EOL> IDENTITY_PROVIDER [ '<STR_LIT:description>' ] = None <EOL> resource = fakes . FakeResource ( None , IDENTITY_PROVIDER , loaded = True ) <EOL> self . identity_providers_mock . create . return_value = resource <EOL> arglist = [ <EOL> '<STR_LIT>' , <EOL> identity_fakes . idp_id , <EOL> ] <EOL> verifylist = [ <EOL> ( '<STR_LIT>' , identity_fakes . idp_id ) , <EOL> ] <EOL> parsed_args = self . check_parser ( self . cmd , arglist , verifylist ) <EOL> columns , data = self . cmd . take_action ( parsed_args ) <EOL> kwargs = { <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT:description>' : None , <EOL> } <EOL> self . identity_providers_mock . create . assert_called_with ( <EOL> id = identity_fakes . idp_id , <EOL> ** kwargs <EOL> ) <EOL> self . assertEqual ( self . columns , columns ) <EOL> datalist = ( <EOL> None , <EOL> False , <EOL> identity_fakes . idp_id , <EOL> identity_fakes . formatted_idp_remote_ids <EOL> ) <EOL> self . assertEqual ( datalist , data ) <EOL> class TestIdentityProviderDelete ( TestIdentityProvider ) : <EOL> def setUp ( self ) : <EOL> super ( TestIdentityProviderDelete , self ) . setUp ( ) <EOL> self . identity_providers_mock . get . return_value = fakes . FakeResource ( <EOL> None , <EOL> copy . deepcopy ( identity_fakes . IDENTITY_PROVIDER ) , <EOL> loaded = True , <EOL> ) <EOL> self . identity_providers_mock . delete . return_value = None <EOL> self . cmd = identity_provider . DeleteIdentityProvider ( self . app , None ) <EOL> def test_delete_identity_provider ( self ) : <EOL> arglist = [ <EOL> identity_fakes . idp_id , <EOL> ] <EOL> verifylist = [ <EOL> ( '<STR_LIT>' , identity_fakes . idp_id ) , <EOL> ] <EOL> parsed_args = self . check_parser ( self . cmd , arglist , verifylist ) <EOL> result = self . cmd . take_action ( parsed_args ) <EOL> self . identity_providers_mock . delete . assert_called_with ( <EOL> identity_fakes . idp_id , <EOL> ) <EOL> self . assertIsNone ( result ) <EOL> class TestIdentityProviderList ( TestIdentityProvider ) : <EOL> def setUp ( self ) : <EOL> super ( TestIdentityProviderList , self ) . setUp ( ) <EOL> self . identity_providers_mock . get . return_value = fakes . FakeResource ( <EOL> None , <EOL> copy . deepcopy ( identity_fakes . IDENTITY_PROVIDER ) , <EOL> loaded = True , <EOL> ) <EOL> self . identity_providers_mock . list . return_value = [ <EOL> fakes . FakeResource ( <EOL> None , <EOL> copy . deepcopy ( identity_fakes . IDENTITY_PROVIDER ) , <EOL> loaded = True , <EOL> ) , <EOL> ] <EOL> self . cmd = identity_provider . ListIdentityProvider ( self . app , None ) <EOL> def test_identity_provider_list_no_options ( 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 . identity_providers_mock . list . assert_called_with ( ) <EOL> collist = ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . assertEqual ( collist , columns ) <EOL> datalist = ( ( <EOL> identity_fakes . idp_id , <EOL> True , <EOL> identity_fakes . idp_description , <EOL> ) , ) <EOL> self . assertEqual ( datalist , tuple ( data ) ) <EOL> class TestIdentityProviderSet ( TestIdentityProvider ) : <EOL> columns = ( <EOL> '<STR_LIT:description>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT:id>' , <EOL> '<STR_LIT>' , <EOL> ) <EOL> datalist = ( <EOL> identity_fakes . idp_description , <EOL> True , <EOL> identity_fakes . idp_id , <EOL> identity_fakes . idp_remote_ids , <EOL> ) <EOL> def setUp ( self ) : <EOL> super ( TestIdentityProviderSet , self ) . setUp ( ) <EOL> self . cmd = identity_provider . SetIdentityProvider ( self . app , None ) <EOL> def test_identity_provider_set_description ( self ) : <EOL> """<STR_LIT>""" <EOL> def prepare ( self ) : <EOL> """<STR_LIT>""" <EOL> updated_idp = copy . deepcopy ( identity_fakes . IDENTITY_PROVIDER ) <EOL> updated_idp [ '<STR_LIT>' ] = False <EOL> resources = fakes . FakeResource ( <EOL> None , <EOL> updated_idp , <EOL> loaded = True <EOL> ) <EOL> self . identity_providers_mock . update . return_value = resources <EOL> prepare ( self ) <EOL> new_description = '<STR_LIT>' <EOL> arglist = [ <EOL> '<STR_LIT>' , new_description , <EOL> identity_fakes . idp_id <EOL> ] <EOL> verifylist = [ <EOL> ( '<STR_LIT>' , identity_fakes . idp_id ) , <EOL> ( '<STR_LIT:description>' , new_description ) , <EOL> ( '<STR_LIT>' , False ) , <EOL> ( '<STR_LIT>' , False ) , <EOL> ( '<STR_LIT>' , None ) <EOL> ] <EOL> parsed_args = self . check_parser ( self . cmd , arglist , verifylist ) <EOL> columns , data = self . cmd . take_action ( parsed_args ) <EOL> self . identity_providers_mock . update . assert_called_with ( <EOL> identity_fakes . idp_id , <EOL> description = new_description , <EOL> ) <EOL> self . assertEqual ( self . columns , columns ) <EOL> datalist = ( <EOL> identity_fakes . idp_description , <EOL> False , <EOL> identity_fakes . idp_id , <EOL> identity_fakes . idp_remote_ids <EOL> ) <EOL> self . assertEqual ( datalist , data ) <EOL> def test_identity_provider_disable ( self ) : <EOL> """<STR_LIT>""" <EOL> def prepare ( self ) : <EOL> """<STR_LIT>""" <EOL> updated_idp = copy . deepcopy ( identity_fakes . IDENTITY_PROVIDER ) <EOL> updated_idp [ '<STR_LIT>' ] = False <EOL> resources = fakes . FakeResource ( <EOL> None , <EOL> updated_idp , <EOL> loaded = True <EOL> ) <EOL> self . identity_providers_mock . update . return_value = resources <EOL> prepare ( self ) <EOL> arglist = [ <EOL> '<STR_LIT>' , identity_fakes . idp_id , <EOL> '<STR_LIT>' , identity_fakes . idp_remote_ids [ <NUM_LIT:0> ] , <EOL> '<STR_LIT>' , identity_fakes . idp_remote_ids [ <NUM_LIT:1> ] <EOL> ] <EOL> verifylist = [ <EOL> ( '<STR_LIT>' , identity_fakes . idp_id ) , <EOL> ( '<STR_LIT:description>' , None ) , <EOL> ( '<STR_LIT>' , False ) , <EOL> ( '<STR_LIT>' , True ) , <EOL> ( '<STR_LIT>' , identity_fakes . idp_remote_ids ) <EOL> ] <EOL> parsed_args = self . check_parser ( self . cmd , arglist , verifylist ) <EOL> columns , data = self . cmd . take_action ( parsed_args ) <EOL> self . identity_providers_mock . update . assert_called_with ( <EOL> identity_fakes . idp_id , <EOL> enabled = False , <EOL> remote_ids = identity_fakes . idp_remote_ids <EOL> ) <EOL> self . assertEqual ( self . columns , columns ) <EOL> datalist = ( <EOL> identity_fakes . idp_description , <EOL> False , <EOL> identity_fakes . idp_id , <EOL> identity_fakes . idp_remote_ids <EOL> ) <EOL> self . assertEqual ( datalist , data ) <EOL> def test_identity_provider_enable ( self ) : <EOL> """<STR_LIT>""" <EOL> def prepare ( self ) : <EOL> """<STR_LIT>""" <EOL> resources = fakes . FakeResource ( <EOL> None , <EOL> copy . deepcopy ( identity_fakes . IDENTITY_PROVIDER ) , <EOL> loaded = True <EOL> ) <EOL> self . identity_providers_mock . update . return_value = resources <EOL> prepare ( self ) <EOL> arglist = [ <EOL> '<STR_LIT>' , identity_fakes . idp_id , <EOL> '<STR_LIT>' , identity_fakes . idp_remote_ids [ <NUM_LIT:0> ] , <EOL> '<STR_LIT>' , identity_fakes . idp_remote_ids [ <NUM_LIT:1> ] <EOL> ] <EOL> verifylist = [ <EOL> ( '<STR_LIT>' , identity_fakes . idp_id ) , <EOL> ( '<STR_LIT:description>' , None ) , <EOL> ( '<STR_LIT>' , True ) , <EOL> ( '<STR_LIT>' , False ) , <EOL> ( '<STR_LIT>' , identity_fakes . idp_remote_ids ) <EOL> ] <EOL> parsed_args = self . check_parser ( self . cmd , arglist , verifylist ) <EOL> columns , data = self . cmd . take_action ( parsed_args ) <EOL> self . identity_providers_mock . update . assert_called_with ( <EOL> identity_fakes . idp_id , enabled = True , <EOL> remote_ids = identity_fakes . idp_remote_ids ) <EOL> self . assertEqual ( self . columns , columns ) <EOL> self . assertEqual ( self . datalist , data ) <EOL> def test_identity_provider_replace_remote_ids ( self ) : <EOL> """<STR_LIT>""" <EOL> def prepare ( self ) : <EOL> """<STR_LIT>""" <EOL> self . new_remote_id = '<STR_LIT>' <EOL> updated_idp = copy . deepcopy ( identity_fakes . IDENTITY_PROVIDER ) <EOL> updated_idp [ '<STR_LIT>' ] = [ self . new_remote_id ] <EOL> resources = fakes . FakeResource ( <EOL> None , <EOL> updated_idp , <EOL> loaded = True <EOL> ) <EOL> self . identity_providers_mock . update . return_value = resources <EOL> prepare ( self ) <EOL> arglist = [ <EOL> '<STR_LIT>' , identity_fakes . idp_id , <EOL> '<STR_LIT>' , self . new_remote_id <EOL> ] <EOL> verifylist = [ <EOL> ( '<STR_LIT>' , identity_fakes . idp_id ) , <EOL> ( '<STR_LIT:description>' , None ) , <EOL> ( '<STR_LIT>' , True ) , <EOL> ( '<STR_LIT>' , False ) , <EOL> ( '<STR_LIT>' , [ self . new_remote_id ] ) <EOL> ] <EOL> parsed_args = self . check_parser ( self . cmd , arglist , verifylist ) <EOL> columns , data = self . cmd . take_action ( parsed_args ) <EOL> self . identity_providers_mock . update . assert_called_with ( <EOL> identity_fakes . idp_id , enabled = True , <EOL> remote_ids = [ self . new_remote_id ] ) <EOL> self . assertEqual ( self . columns , columns ) <EOL> datalist = ( <EOL> identity_fakes . idp_description , <EOL> True , <EOL> identity_fakes . idp_id , <EOL> [ self . new_remote_id ] <EOL> ) <EOL> self . assertEqual ( datalist , data ) <EOL> def test_identity_provider_replace_remote_ids_file ( self ) : <EOL> """<STR_LIT>""" <EOL> def prepare ( self ) : <EOL> """<STR_LIT>""" <EOL> self . new_remote_id = '<STR_LIT>' <EOL> updated_idp = copy . deepcopy ( identity_fakes . IDENTITY_PROVIDER ) <EOL> updated_idp [ '<STR_LIT>' ] = [ self . new_remote_id ] <EOL> resources = fakes . FakeResource ( <EOL> None , <EOL> updated_idp , <EOL> loaded = True <EOL> ) <EOL> self . identity_providers_mock . update . return_value = resources <EOL> prepare ( self ) <EOL> arglist = [ <EOL> '<STR_LIT>' , identity_fakes . idp_id , <EOL> '<STR_LIT>' , self . new_remote_id , <EOL> ] <EOL> verifylist = [ <EOL> ( '<STR_LIT>' , identity_fakes . idp_id ) , <EOL> ( '<STR_LIT:description>' , None ) , <EOL> ( '<STR_LIT>' , True ) , <EOL> ( '<STR_LIT>' , False ) , <EOL> ( '<STR_LIT>' , self . new_remote_id ) , <EOL> ] <EOL> parsed_args = self . check_parser ( self . cmd , arglist , verifylist ) <EOL> mocker = mock . Mock ( ) <EOL> mocker . return_value = self . new_remote_id <EOL> with mock . patch ( "<STR_LIT>" <EOL> "<STR_LIT>" , mocker ) : <EOL> columns , data = self . cmd . take_action ( parsed_args ) <EOL> self . identity_providers_mock . update . assert_called_with ( <EOL> identity_fakes . idp_id , enabled = True , <EOL> remote_ids = [ self . new_remote_id ] ) <EOL> self . assertEqual ( self . columns , columns ) <EOL> datalist = ( <EOL> identity_fakes . idp_description , <EOL> True , <EOL> identity_fakes . idp_id , <EOL> [ self . new_remote_id ] <EOL> ) <EOL> self . assertEqual ( datalist , data ) <EOL> def test_identity_provider_no_options ( self ) : <EOL> def prepare ( self ) : <EOL> """<STR_LIT>""" <EOL> resources = fakes . FakeResource ( <EOL> None , <EOL> copy . deepcopy ( identity_fakes . IDENTITY_PROVIDER ) , <EOL> loaded = True <EOL> ) <EOL> self . identity_providers_mock . get . return_value = resources <EOL> resources = fakes . FakeResource ( <EOL> None , <EOL> copy . deepcopy ( identity_fakes . IDENTITY_PROVIDER ) , <EOL> loaded = True , <EOL> ) <EOL> self . identity_providers_mock . update . return_value = resources <EOL> prepare ( self ) <EOL> arglist = [ <EOL> identity_fakes . idp_id , <EOL> ] <EOL> verifylist = [ <EOL> ( '<STR_LIT>' , identity_fakes . idp_id ) , <EOL> ( '<STR_LIT>' , False ) , <EOL> ( '<STR_LIT>' , False ) , <EOL> ( '<STR_LIT>' , None ) <EOL> ] <EOL> parsed_args = self . check_parser ( self . cmd , arglist , verifylist ) <EOL> columns , data = self . cmd . take_action ( parsed_args ) <EOL> self . assertIsNone ( columns ) <EOL> self . assertIsNone ( data ) <EOL> class TestIdentityProviderShow ( TestIdentityProvider ) : <EOL> def setUp ( self ) : <EOL> super ( TestIdentityProviderShow , self ) . setUp ( ) <EOL> ret = fakes . FakeResource ( <EOL> None , <EOL> copy . deepcopy ( identity_fakes . IDENTITY_PROVIDER ) , <EOL> loaded = True , <EOL> ) <EOL> self . identity_providers_mock . get . return_value = ret <EOL> self . cmd = identity_provider . ShowIdentityProvider ( self . app , None ) <EOL> def test_identity_provider_show ( self ) : <EOL> arglist = [ <EOL> identity_fakes . idp_id , <EOL> ] <EOL> verifylist = [ <EOL> ( '<STR_LIT>' , identity_fakes . idp_id ) , <EOL> ] <EOL> parsed_args = self . check_parser ( self . cmd , arglist , verifylist ) <EOL> columns , data = self . cmd . take_action ( parsed_args ) <EOL> self . identity_providers_mock . get . assert_called_with ( <EOL> identity_fakes . idp_id , <EOL> ) <EOL> collist = ( '<STR_LIT:description>' , '<STR_LIT>' , '<STR_LIT:id>' , '<STR_LIT>' ) <EOL> self . assertEqual ( collist , columns ) <EOL> datalist = ( <EOL> identity_fakes . idp_description , <EOL> True , <EOL> identity_fakes . idp_id , <EOL> identity_fakes . formatted_idp_remote_ids <EOL> ) <EOL> self . assertEqual ( datalist , data ) </s>
