def test_get_client_unauthenticated(self): ident = self.identity ident.authenticated = False svc = "fake" region = utils.random_unicode() pub = utils.random_unicode() priv = utils.random_unicode() ep_dict = {"publicURL": pub, "privateURL": priv, "tenantId": "aa"} rgn = "FOO" clt = fakes.FakeClient() ep = fakes.FakeEndpoint(ep_dict, svc, rgn, self.identity) ep._get_client = Mock(return_value=clt) ident.services[svc].endpoints = {region: ep} self.assertRaises(exc.NotAuthenticated, ident.get_client, svc, region)
def test_get_client_private(self): ident = self.identity ident.authenticated = True svc = "fake" region = utils.random_unicode() pub = utils.random_unicode() priv = utils.random_unicode() ep_dict = {"publicURL": pub, "privateURL": priv, "tenantId": "aa"} rgn = "FOO" clt = fakes.FakeClient() ep = fakes.FakeEndpoint(ep_dict, svc, rgn, self.identity) ep._get_client = Mock(return_value=clt) ident.services[svc].endpoints = {region: ep} ret = ident.get_client(svc, region, public=False) self.assertEqual(ret, clt) ep._get_client.assert_called_once_with(cached=True, public=False, client_class=None)
def test_ep_create_client_compute(self): svc = self.service pub = utils.random_unicode() priv = utils.random_unicode() ep_dict = {"publicURL": pub, "privateURL": priv, "tenantId": "aa"} rgn = utils.random_unicode().upper() ep = fakes.FakeEndpoint(ep_dict, svc, rgn, self.identity) vssl = random.choice((True, False)) public = random.choice((True, False)) sav_gs = pyos.get_setting pyos.get_setting = Mock(return_value=vssl) sav_conn = pyos.connect_to_cloudservers fake_client = fakes.FakeClient() fake_client.identity = self.identity pyos.connect_to_cloudservers = Mock(return_value=fake_client) ep.service = "compute" ret = ep._create_client(None, None, public) self.assertEqual(ret, fake_client) pyos.connect_to_cloudservers.assert_called_once_with(region=ep.region, context=ep.identity) pyos.connect_to_cloudservers = sav_conn pyos.get_setting = sav_gs
def setUp(self): self.fake_api = fakes.FakeClient() self.manager = manager.BaseManager(self.fake_api)