<s> import mock <EOL> from oslo_config import cfg <EOL> cfg . CONF . import_group ( '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> import keystoneclient . exceptions as kc_exception <EOL> from solum . common import exception <EOL> from solum . common import solum_keystoneclient <EOL> from solum . tests import base <EOL> from solum . tests import utils <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> class KeystoneClientTest ( base . BaseTestCase ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> super ( KeystoneClientTest , self ) . setUp ( ) <EOL> dummy_url = '<STR_LIT>' <EOL> self . ctx = utils . dummy_context ( ) <EOL> self . ctx . auth_url = dummy_url <EOL> self . ctx . auth_token = '<STR_LIT>' <EOL> self . ctx . auth_token_info = None <EOL> cfg . CONF . set_override ( '<STR_LIT>' , dummy_url , <EOL> group = '<STR_LIT>' ) <EOL> cfg . CONF . set_override ( '<STR_LIT>' , '<STR_LIT>' , <EOL> group = '<STR_LIT>' ) <EOL> cfg . CONF . set_override ( '<STR_LIT>' , '<STR_LIT>' , <EOL> group = '<STR_LIT>' ) <EOL> cfg . CONF . set_override ( '<STR_LIT>' , '<STR_LIT>' , <EOL> group = '<STR_LIT>' ) <EOL> def test_init_v3_token ( self , mock_ks ) : <EOL> """<STR_LIT>""" <EOL> self . ctx . tenant = None <EOL> self . ctx . trust_id = None <EOL> solum_ks_client = solum_keystoneclient . KeystoneClientV3 ( self . ctx ) <EOL> solum_ks_client . client <EOL> self . assertIsNotNone ( solum_ks_client . _client ) <EOL> mock_ks . assert_called_once_with ( token = '<STR_LIT>' , project_id = None , <EOL> auth_url = '<STR_LIT>' , <EOL> endpoint = '<STR_LIT>' ) <EOL> mock_ks . return_value . authenticate . assert_called_once_with ( ) <EOL> def test_init_v3_bad_nocreds ( self , mock_ks ) : <EOL> """<STR_LIT>""" <EOL> self . ctx . auth_token = None <EOL> self . ctx . trust_id = None <EOL> self . ctx . username = None <EOL> solum_ks_client = solum_keystoneclient . KeystoneClientV3 ( self . ctx ) <EOL> self . assertRaises ( exception . AuthorizationFailure , <EOL> solum_ks_client . _v3_client_init ) <EOL> def test_init_trust_token_access ( self , mock_ks ) : <EOL> """<STR_LIT>""" <EOL> self . ctx . tenant = '<STR_LIT>' <EOL> self . ctx . trust_id = None <EOL> self . ctx . auth_token_info = { '<STR_LIT>' : { '<STR_LIT>' : { '<STR_LIT:id>' : '<STR_LIT>' } } } <EOL> solum_ks_client = solum_keystoneclient . KeystoneClientV3 ( self . ctx ) <EOL> solum_ks_client . client <EOL> self . assertIsNotNone ( solum_ks_client . _client ) <EOL> mock_ks . assert_called_once_with ( auth_ref = { '<STR_LIT:version>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:id>' : '<STR_LIT>' } } , <EOL> endpoint = '<STR_LIT>' , <EOL> auth_url = '<STR_LIT>' ) <EOL> def test_init_trust_token_token ( self , mock_ks ) : <EOL> self . ctx . tenant = None <EOL> self . ctx . trust_id = None <EOL> self . ctx . auth_token_info = { '<STR_LIT>' : { } } <EOL> solum_ks_client = solum_keystoneclient . KeystoneClientV3 ( self . ctx ) <EOL> solum_ks_client . client <EOL> self . assertIsNotNone ( solum_ks_client . _client ) <EOL> mock_ks . assert_called_once_with ( auth_ref = { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:version>' : '<STR_LIT>' } , <EOL> endpoint = '<STR_LIT>' , <EOL> auth_url = '<STR_LIT>' ) <EOL> def test_init_trust_token_none ( self , mock_ks ) : <EOL> self . ctx . tenant = None <EOL> self . ctx . trust_id = None <EOL> self . ctx . auth_token_info = { '<STR_LIT>' : '<STR_LIT>' } <EOL> solum_ks_client = solum_keystoneclient . KeystoneClientV3 ( self . ctx ) <EOL> self . assertRaises ( exception . AuthorizationFailure , <EOL> solum_ks_client . _v3_client_init ) <EOL> def test_create_trust_context_trust_id ( self , mock_ks ) : <EOL> """<STR_LIT>""" <EOL> self . ctx . trust_id = '<STR_LIT>' <EOL> solum_ks_client = solum_keystoneclient . KeystoneClientV3 ( self . ctx ) <EOL> trust_context = solum_ks_client . create_trust_context ( ) <EOL> self . assertEqual ( self . ctx . to_dict ( ) , trust_context . to_dict ( ) ) <EOL> mock_ks . assert_called_once_with ( username = '<STR_LIT>' , <EOL> auth_url = '<STR_LIT>' , <EOL> password = '<STR_LIT>' , <EOL> endpoint = '<STR_LIT>' , <EOL> trust_id = '<STR_LIT>' ) <EOL> mock_ks . return_value . authenticate . assert_called_once_with ( ) <EOL> def test_create_trust_context_trust_create ( self , mock_ks ) : <EOL> """<STR_LIT>""" <EOL> class FakeTrust ( object ) : <EOL> id = '<STR_LIT>' <EOL> cfg . CONF . set_override ( '<STR_LIT>' , <EOL> [ '<STR_LIT>' ] ) <EOL> getter_mock = mock . PropertyMock ( side_effect = [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> type ( mock_ks . return_value . auth_ref ) . user_id = getter_mock <EOL> mock_ks . return_value . auth_ref . project_id = '<STR_LIT>' <EOL> mock_ks . return_value . trusts . create . return_value = FakeTrust ( ) <EOL> self . ctx . trust_id = None <EOL> solum_ks_client = solum_keystoneclient . KeystoneClientV3 ( self . ctx ) <EOL> trust_context = solum_ks_client . create_trust_context ( ) <EOL> expected = [ mock . call ( username = '<STR_LIT>' , <EOL> project_name = '<STR_LIT>' , <EOL> password = '<STR_LIT>' , <EOL> auth_url = '<STR_LIT>' , <EOL> endpoint = '<STR_LIT>' ) , <EOL> mock . call ( token = '<STR_LIT>' , <EOL> project_id = '<STR_LIT>' , <EOL> auth_url = '<STR_LIT>' , <EOL> endpoint = '<STR_LIT>' ) ] <EOL> self . assertEqual ( expected , mock_ks . call_args_list ) <EOL> self . assertEqual ( [ mock . call ( ) , mock . call ( ) ] , <EOL> mock_ks . return_value . authenticate . call_args_list ) <EOL> self . assertEqual ( '<STR_LIT>' , trust_context . trust_id ) <EOL> mock_ks . return_value . trusts . create . assert_called_once_with ( <EOL> trustor_user = '<STR_LIT>' , <EOL> trustee_user = '<STR_LIT>' , <EOL> project = '<STR_LIT>' , <EOL> impersonation = True , <EOL> role_names = [ '<STR_LIT>' ] ) <EOL> def test_init_admin_client_denied ( self , mock_ks ) : <EOL> """<STR_LIT>""" <EOL> self . ctx . username = None <EOL> self . ctx . password = None <EOL> self . ctx . trust_id = None <EOL> mock_ks . return_value . authenticate . return_value = False <EOL> solum_ks_client = solum_keystoneclient . KeystoneClientV3 ( self . ctx ) <EOL> def get_admin_client ( ) : <EOL> solum_ks_client . admin_client <EOL> self . assertRaises ( exception . AuthorizationFailure , <EOL> get_admin_client ) <EOL> def test_init_lp_admin_client_denied ( self , mock_ks ) : <EOL> """<STR_LIT>""" <EOL> self . ctx . username = None <EOL> self . ctx . password = None <EOL> self . ctx . trust_id = None <EOL> mock_ks . return_value . authenticate . return_value = False <EOL> solum_ks_client = solum_keystoneclient . KeystoneClientV3 ( self . ctx ) <EOL> def get_lp_admin_client ( ) : <EOL> solum_ks_client . lp_admin_client <EOL> self . assertRaises ( exception . AuthorizationFailure , <EOL> get_lp_admin_client ) <EOL> def test_init_with_no_context ( self , mock_ks ) : <EOL> """<STR_LIT>""" <EOL> mock_ks . return_value . authenticate . return_value = False <EOL> solum_ks_client = solum_keystoneclient . KeystoneClientV3 ( None ) <EOL> self . assertEqual ( solum_ks_client . endpoint , <EOL> '<STR_LIT>' ) <EOL> def test_trust_init_fail ( self , mock_ks ) : <EOL> """<STR_LIT>""" <EOL> self . ctx . username = None <EOL> self . ctx . auth_token = None <EOL> self . ctx . trust_id = '<STR_LIT>' <EOL> mock_ks . return_value . auth_ref . trust_scoped = False <EOL> self . assertRaises ( exception . AuthorizationFailure , <EOL> solum_keystoneclient . KeystoneClientV3 , self . ctx ) <EOL> def test_trust_init_token ( self , mock_ks ) : <EOL> """<STR_LIT>""" <EOL> self . ctx . username = None <EOL> self . ctx . trust_id = '<STR_LIT>' <EOL> solum_ks_client = solum_keystoneclient . KeystoneClientV3 ( self . ctx ) <EOL> self . assertIsNotNone ( solum_ks_client . _client ) <EOL> mock_ks . assert_called_once_with ( username = '<STR_LIT>' , <EOL> auth_url = '<STR_LIT>' , <EOL> password = '<STR_LIT>' , <EOL> endpoint = '<STR_LIT>' , <EOL> trust_id = '<STR_LIT>' ) <EOL> mock_ks . return_value . authenticate . assert_called_once_with ( ) <EOL> def test_delete_trust ( self , mock_ks ) : <EOL> """<STR_LIT>""" <EOL> mock_ks . return_value . trusts . delete . return_value = None <EOL> solum_ks_client = solum_keystoneclient . KeystoneClientV3 ( self . ctx ) <EOL> self . assertIsNone ( solum_ks_client . delete_trust ( trust_id = '<STR_LIT>' ) ) <EOL> mock_ks . return_value . trusts . delete . assert_called_once_with ( '<STR_LIT>' ) <EOL> def test_delete_trust_not_found ( self , mock_ks ) : <EOL> """<STR_LIT>""" <EOL> mock_delete = mock_ks . return_value . trusts . delete <EOL> mock_delete . side_effect = kc_exception . NotFound ( ) <EOL> solum_ks_client = solum_keystoneclient . KeystoneClientV3 ( self . ctx ) <EOL> self . assertIsNone ( solum_ks_client . delete_trust ( trust_id = '<STR_LIT>' ) ) </s>
