How to use _get_credentials_provider method in tempest

Best Python code snippet using tempest_python

test_credentials_factory.py

Source:test_credentials_factory.py Github

copy

Full Screen

...28 self.assertEqual(new_cls._get_credentials_provider, mock_gcp)29 self.assertEqual(new_cls.are_roles_available, mock_ara)30 self.assertEqual(new_cls.get_client_manager, mock_gcm)31 @mock.patch.object(creds, 'get_credentials_provider')32 def test_get_credentials_provider(self, mock_gcp):33 cls = mock.Mock()34 del cls.force_tenant_isolation35 del cls._creds_provider36 self._do_creds_provider_test(cls, mock_gcp)37 @mock.patch.object(creds, 'get_credentials_provider')38 def test_get_credentials_provider_with_tenant_iso(self, mock_gcp):39 cls = mock.Mock()40 self._do_creds_provider_test(cls, mock_gcp, tenant_iso=True)41 @mock.patch.object(creds, 'get_credentials_provider')42 def test_get_credentials_provider_none_creds_provider(self, mock_gcp):43 cls = mock.Mock()44 del cls.force_tenant_isolation45 cls._creds_provider = None46 self._do_creds_provider_test(cls, mock_gcp)47 @mock.patch.object(creds, 'get_credentials_provider')48 def test_get_credentials_provider_with_different_name(self, mock_gcp):49 cls = mock.Mock()50 del cls.force_tenant_isolation51 cls._creds_provider.__name__ = 'notfoo'52 self._do_creds_provider_test(cls, mock_gcp)53 @mock.patch.object(creds, 'get_credentials_provider')54 def test_get_credentials_already_has_provider(self, mock_gcp):55 cls = mock.Mock()56 cls.__name__ = 'foo'57 mock_prov = mock.Mock()58 mock_prov.name = cls.__name__59 cls._creds_provider = mock_prov60 prov = creds._get_credentials_provider(cls)61 self.assertEqual(mock_prov, prov)62 mock_gcp.assert_not_called()63 def test_are_roles_available(self):64 cls = mock.Mock()65 mock_prov = mock.Mock()66 mock_prov.are_roles_available.return_value = False67 cls._get_credentials_provider.return_value = mock_prov68 roles = ['foo', 'bar']69 are_avail = creds._are_roles_available(cls, roles)70 self.assertFalse(are_avail)71 mock_prov.are_roles_available.assert_called_once_with(roles)72 def test_are_roles_available_not_on_cred_provider(self):73 cls = mock.Mock()74 mock_prov = mock.Mock()75 del mock_prov.are_roles_available76 cls._get_credentials_provider.return_value = mock_prov77 roles = ['foo', 'bar']78 are_avail = creds._are_roles_available(cls, roles)79 self.assertTrue(are_avail)80 def test_get_client_manager(self):81 cls = mock.Mock()82 cls.are_roles_available.return_value = True83 self._do_client_manager_test(cls, roles=['foo', 'bar'])84 cls.are_roles_available.assert_called_once_with(['foo', 'bar'])85 def test_get_client_manager_without_roles(self):86 self._do_client_manager_test(mock.Mock())87 def test_get_client_manager_raises_skip(self):88 cls = mock.Mock()89 cls.__name__ = 'foo'90 cls.are_roles_available.return_value = False91 class MyException(Exception):92 pass93 cls.skipException = MyException94 self.assertRaises(MyException, creds._get_client_manager,95 cls, roles=['foo'])96 @mock.patch.object(t_creds, 'get_credentials_provider')97 @mock.patch.object(t_creds, '_get_preprov_provider_params')98 @mock.patch.object(creds, 'CONF')99 def test_public_get_credentials_provider(self, mock_conf,100 mock_params, mock_gcp):101 cls_name = 'ExactRoleMatchingPreProvisionedCredentialProvider'102 mock_conf.auth.test_accounts_file = 'foo.yaml'103 name = 'foo'104 params = {'foo': 'bar'}105 mock_params.return_value = params106 kwargs = {'network_resources': ['net1', 'net2'],107 'force_tenant_isolation': False, 'identity_version': 'v3'}108 with mock.patch.object(ppc, cls_name) as mock_creds:109 mock_provider = mock.Mock()110 mock_creds.return_value = mock_provider111 prov = creds.get_credentials_provider(name, **kwargs)112 self.assertEqual(mock_provider, prov)113 mock_gcp.assert_called_once_with(name, **kwargs)114 mock_params.assert_called_once_with()115 kwargs.update(params)116 del kwargs['force_tenant_isolation']117 del kwargs['network_resources']118 mock_creds.assert_called_once_with(name=name, **kwargs)119 @mock.patch.object(t_creds, 'get_credentials_provider')120 @mock.patch.object(creds, 'CONF')121 def test_get_credentials_provider_no_accounts_file(self, mock_conf,122 mock_gcp):123 mock_conf.auth.test_accounts_file = None124 mock_prov = mock.Mock()125 mock_gcp.return_value = mock_prov126 name = 'foo'127 kwargs = {'network_resources': ['net1', 'net2'],128 'force_tenant_isolation': True, 'identity_version': 'v3'}129 prov = creds.get_credentials_provider(name, **kwargs)130 self.assertEqual(mock_prov, prov)131 mock_gcp.assert_called_once_with(name, **kwargs)132 def _do_creds_provider_test(self, mock_cls, mock_get, tenant_iso=False):133 mock_cls.__name__ = 'foo'134 mock_cls.network_resources = ['net1', 'net2']135 mock_cls.get_identity_version = mock.Mock()136 mock_cls.get_identity_version.return_value = 'v3'137 mock_cls.force_tenant_isolation = tenant_iso138 mock_prov = mock.Mock()139 mock_get.return_value = mock_prov140 provider = creds._get_credentials_provider(mock_cls)141 self.assertEqual(provider, mock_prov)142 self.assertEqual(provider, mock_cls._creds_provider)143 mock_get.assert_called_once_with(144 name=mock_cls.__name__,145 network_resources=mock_cls.network_resources,146 force_tenant_isolation=tenant_iso,147 identity_version=mock_cls.get_identity_version())148 def _do_client_manager_test(self, cls, roles=None):149 mock_gcm = mock.Mock()150 mock_man = mock.Mock()151 mock_gcm.return_value = mock_man152 my_super = mock.Mock()153 my_super.get_client_manager = mock_gcm154 with mock.patch('cinnamon_role.credentials_factory.super') as mock_sup:...

Full Screen

Full Screen

test_base_test.py

Source:test_base_test.py Github

copy

Full Screen

1# Copyright 2016 IBM Corp.2#3# Licensed under the Apache License, Version 2.0 (the "License"); you may4# not use this file except in compliance with the License. You may obtain5# a copy of the License at6#7# http://www.apache.org/licenses/LICENSE-2.08#9# Unless required by applicable law or agreed to in writing, software10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the12# License for the specific language governing permissions and limitations13# under the License.1415import mock1617from tempest import clients18from tempest.common import credentials_factory as credentials19from tempest.common import fixed_network20from tempest import config21from tempest import test22from tempest.tests import fake_config23from tempest.tests.lib import base242526class TestBaseTestCase(base.TestCase):27 def setUp(self):28 super(TestBaseTestCase, self).setUp()29 self.useFixture(fake_config.ConfigFixture())30 self.fixed_network_name = 'fixed-net'31 config.CONF.compute.fixed_network_name = self.fixed_network_name32 config.CONF.service_available.neutron = True3334 @mock.patch.object(test.BaseTestCase, 'get_client_manager')35 @mock.patch.object(test.BaseTestCase, '_get_credentials_provider')36 @mock.patch.object(fixed_network, 'get_tenant_network')37 def test_get_tenant_network(self, mock_gtn, mock_gprov, mock_gcm):38 net_client = mock.Mock()39 mock_prov = mock.Mock()40 mock_gcm.return_value.compute_networks_client = net_client41 mock_gprov.return_value = mock_prov4243 test.BaseTestCase.get_tenant_network()4445 mock_gcm.assert_called_once_with(credential_type='primary')46 mock_gprov.assert_called_once_with()47 mock_gtn.assert_called_once_with(mock_prov, net_client,48 self.fixed_network_name)4950 @mock.patch.object(test.BaseTestCase, 'get_client_manager')51 @mock.patch.object(test.BaseTestCase, '_get_credentials_provider')52 @mock.patch.object(fixed_network, 'get_tenant_network')53 @mock.patch.object(test.BaseTestCase, 'get_identity_version')54 @mock.patch.object(credentials, 'is_admin_available')55 @mock.patch.object(clients, 'Manager')56 def test_get_tenant_network_with_nova_net(self, mock_man, mock_iaa,57 mock_giv, mock_gtn, mock_gcp,58 mock_gcm):59 config.CONF.service_available.neutron = False60 mock_prov = mock.Mock()61 mock_admin_man = mock.Mock()62 mock_iaa.return_value = True63 mock_gcp.return_value = mock_prov64 mock_man.return_value = mock_admin_man6566 test.BaseTestCase.get_tenant_network()6768 mock_man.assert_called_once_with(69 mock_prov.get_admin_creds.return_value)70 mock_iaa.assert_called_once_with(71 identity_version=mock_giv.return_value)72 mock_gcp.assert_called_once_with()73 mock_gtn.assert_called_once_with(74 mock_prov, mock_admin_man.compute_networks_client,75 self.fixed_network_name)7677 @mock.patch.object(test.BaseTestCase, 'get_client_manager')78 @mock.patch.object(test.BaseTestCase, '_get_credentials_provider')79 @mock.patch.object(fixed_network, 'get_tenant_network')80 def test_get_tenant_network_with_alt_creds(self, mock_gtn, mock_gprov,81 mock_gcm):82 net_client = mock.Mock()83 mock_prov = mock.Mock()84 mock_gcm.return_value.compute_networks_client = net_client85 mock_gprov.return_value = mock_prov8687 test.BaseTestCase.get_tenant_network(credentials_type='alt')8889 mock_gcm.assert_called_once_with(credential_type='alt')90 mock_gprov.assert_called_once_with()91 mock_gtn.assert_called_once_with(mock_prov, net_client,92 self.fixed_network_name)9394 @mock.patch.object(test.BaseTestCase, 'get_client_manager')95 @mock.patch.object(test.BaseTestCase, '_get_credentials_provider')96 @mock.patch.object(fixed_network, 'get_tenant_network')97 def test_get_tenant_network_with_role_creds(self, mock_gtn, mock_gprov,98 mock_gcm):99 net_client = mock.Mock()100 mock_prov = mock.Mock()101 mock_gcm.return_value.compute_networks_client = net_client102 mock_gprov.return_value = mock_prov103 creds = ['foo_type', 'role1']104105 test.BaseTestCase.get_tenant_network(credentials_type=creds)106107 mock_gcm.assert_called_once_with(roles=['role1'])108 mock_gprov.assert_called_once_with()109 mock_gtn.assert_called_once_with(mock_prov, net_client, ...

Full Screen

Full Screen

credentials_factory.py

Source:credentials_factory.py Github

copy

Full Screen

...24 cls._get_credentials_provider = classmethod(_get_credentials_provider)25 cls.are_roles_available = classmethod(_are_roles_available)26 cls.get_client_manager = classmethod(_get_client_manager)27 return cls28def _get_credentials_provider(cls):29 # The new _get_credentails_provider() of the class30 # it runs the local get_credentials_provider() if _creds_provider is31 # not already set32 if (not hasattr(cls, '_creds_provider') or not cls._creds_provider or33 not cls._creds_provider.name == cls.__name__):34 force_tenant_isolation = getattr(cls, 'force_tenant_isolation',35 False)36 cls._creds_provider = get_credentials_provider(37 name=cls.__name__, network_resources=cls.network_resources,38 force_tenant_isolation=force_tenant_isolation,39 identity_version=cls.get_identity_version())40 return cls._creds_provider41def _are_roles_available(cls, roles):42 # A new method that checks to see if there exists a user with exactly43 # the roles specified.44 # Calls into the cred provider to get that information, if the45 # creds provider can supply it.46 cred_provider = cls._get_credentials_provider()47 # Only check if the roles are available if we're using48 # the custom cred provider, otherwise return True49 # so we don't hold things up50 if hasattr(cred_provider, 'are_roles_available'):51 return cred_provider.are_roles_available(roles)52 else:53 return True54def _get_client_manager(cls, credential_type=None, roles=None,55 force_new=None):56 # The new get_client_manager() method of the class.57 # It raises a skip exception if there is no user with exactly the roles58 # on a user.59 if roles:60 if not cls.are_roles_available(roles):...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run tempest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful