def test_get_glance_api(self): self.mox.StubOutClassWithMocks(glance_client, 'Client') glance_client.Client(TEST_HOSTNAME, TEST_PORT) self.mox.StubOutWithMock(api, 'url_for') api.url_for(IsA(http.HttpRequest), 'glance').AndReturn(TEST_URL) self.mox.ReplayAll() self.assertIsNotNone(api.glance_api(self.request)) self.mox.VerifyAll()
def get_openrc(request): nova_url = api.url_for(request, 'identity', public=True) try: ec2_url = api.url_for(request, 'ec2', public=True) except api.ServiceCatalogException: ec2_url = '' data = dict(user=request.user, nova_url=nova_url, ec2_url=ec2_url) response = shortcuts.render_to_response('auth_openrc', data, context_instance=template.RequestContext(request), mimetype="text") response['Content-Disposition'] = 'attachment; filename=openrc.sh' return response
def test_get_extras_api(self): self.mox.StubOutClassWithMocks(OSExtras, "Extras") OSExtras.Extras(auth_token=TEST_TOKEN, management_url=TEST_URL) self.mox.StubOutWithMock(api, "url_for") api.url_for(IsA(http.HttpRequest), "nova").AndReturn(TEST_URL) api.url_for(IsA(http.HttpRequest), "nova").AndReturn(TEST_URL) self.mox.ReplayAll() self.assertIsNotNone(api.extras_api(self.request)) self.mox.VerifyAll()
def test_get_admin_api(self): self.mox.StubOutClassWithMocks(OSAdmin, "Admin") OSAdmin.Admin(auth_token=TEST_TOKEN, management_url=TEST_URL) self.mox.StubOutWithMock(api, "url_for") api.url_for(IsA(http.HttpRequest), "nova", True).AndReturn(TEST_URL) api.url_for(IsA(http.HttpRequest), "nova", True).AndReturn(TEST_URL) self.mox.ReplayAll() self.assertIsNotNone(api.admin_api(self.request)) self.mox.VerifyAll()
def test_get_account_api(self): self.mox.StubOutClassWithMocks(OSExtras, "Account") OSExtras.Account(auth_token=TEST_TOKEN, management_url=TEST_URL) self.mox.StubOutWithMock(api, "url_for") api.url_for(IsA(http.HttpRequest), "identity", True).AndReturn(TEST_URL) api.url_for(IsA(http.HttpRequest), "identity", True).AndReturn(TEST_URL) self.mox.ReplayAll() self.assertIsNotNone(api.account_api(self.request)) self.mox.VerifyAll()
def test_get_glance_api(self): self.mox.StubOutClassWithMocks(glance_client, "Client") client_instance = glance_client.Client(TEST_HOSTNAME, TEST_PORT, auth_tok=TEST_TOKEN) # Normally ``auth_tok`` is set in ``Client.__init__``, but mox doesn't # duplicate that behavior so we set it manually. client_instance.auth_tok = TEST_TOKEN self.mox.StubOutWithMock(api, "url_for") api.url_for(IsA(http.HttpRequest), "glance").AndReturn(TEST_URL) self.mox.ReplayAll() ret_val = api.glance_api(self.request) self.assertIsNotNone(ret_val) self.assertEqual(ret_val.auth_tok, TEST_TOKEN) self.mox.VerifyAll()
def test_url_for(self): GLANCE_URL = "http://glance/glanceapi/" NOVA_URL = "http://nova/novapi/" url = api.url_for(self.request, "glance") self.assertEqual(url, GLANCE_URL + "internal") url = api.url_for(self.request, "glance", admin=False) self.assertEqual(url, GLANCE_URL + "internal") url = api.url_for(self.request, "glance", admin=True) self.assertEqual(url, GLANCE_URL + "admin") url = api.url_for(self.request, "nova") self.assertEqual(url, NOVA_URL + "internal") url = api.url_for(self.request, "nova", admin=False) self.assertEqual(url, NOVA_URL + "internal") url = api.url_for(self.request, "nova", admin=True) self.assertEqual(url, NOVA_URL + "admin") self.assertNotIn("notAnApi", self.request.user.service_catalog, "Select a new nonexistent service catalog key") with self.assertRaises(api.ServiceCatalogException): url = api.url_for(self.request, "notAnApi")
def test_url_for(self): GLANCE_URL = 'http://glance/glanceapi/' NOVA_URL = 'http://nova/novapi/' url = api.url_for(self.request, 'glance') self.assertEqual(url, GLANCE_URL + 'internal') url = api.url_for(self.request, 'glance', admin=False) self.assertEqual(url, GLANCE_URL + 'internal') url = api.url_for(self.request, 'glance', admin=True) self.assertEqual(url, GLANCE_URL + 'admin') url = api.url_for(self.request, 'nova') self.assertEqual(url, NOVA_URL + 'internal') url = api.url_for(self.request, 'nova', admin=False) self.assertEqual(url, NOVA_URL + 'internal') url = api.url_for(self.request, 'nova', admin=True) self.assertEqual(url, NOVA_URL + 'admin') self.assertNotIn('notAnApi', self.request.user.service_catalog, 'Select a new nonexistent service catalog key') with self.assertRaises(api.ServiceCatalogException): url = api.url_for(self.request, 'notAnApi')
def test_get_compute_api(self): class ComputeClient(object): __slots__ = ['auth_token', 'management_url'] self.mox.StubOutClassWithMocks(OSCompute, 'Compute') compute_api = OSCompute.Compute(auth_token=TEST_TOKEN, management_url=TEST_URL) compute_api.client = ComputeClient() self.mox.StubOutWithMock(api, 'url_for') # called three times? Looks like a good place for optimization api.url_for(IsA(http.HttpRequest), 'nova').AndReturn(TEST_URL) api.url_for(IsA(http.HttpRequest), 'nova').AndReturn(TEST_URL) api.url_for(IsA(http.HttpRequest), 'nova').AndReturn(TEST_URL) self.mox.ReplayAll() compute_api = api.compute_api(self.request) self.assertIsNotNone(compute_api) self.assertEqual(compute_api.client.auth_token, TEST_TOKEN) self.assertEqual(compute_api.client.management_url, TEST_URL) self.mox.VerifyAll()
def test_url_for(self): GLANCE_URL = 'http://glance/glanceapi/' NOVA_URL = 'http://nova/novapi/' # NOTE: serviceCatalog is now constructed as part of the user object # serviceCatalog = { # 'glance': [{'adminURL': GLANCE_URL + 'admin', # 'internalURL': GLANCE_URL + 'internal'}, # ], # 'nova': [{'adminURL': NOVA_URL + 'admin', # 'internalURL': NOVA_URL + 'internal'}, # ], # } url = api.url_for(self.request, 'glance') self.assertEqual(url, GLANCE_URL + 'internal') url = api.url_for(self.request, 'glance', admin=False) self.assertEqual(url, GLANCE_URL + 'internal') url = api.url_for(self.request, 'glance', admin=True) self.assertEqual(url, GLANCE_URL + 'admin') url = api.url_for(self.request, 'nova') self.assertEqual(url, NOVA_URL + 'internal') url = api.url_for(self.request, 'nova', admin=False) self.assertEqual(url, NOVA_URL + 'internal') url = api.url_for(self.request, 'nova', admin=True) self.assertEqual(url, NOVA_URL + 'admin')