def test_disassociate_post_with_exception(self): self.mox.StubOutWithMock(api, 'tenant_floating_ip_list') api.tenant_floating_ip_list(IsA(http.HttpRequest)).\ AndReturn(self.floating_ips) self.mox.StubOutWithMock(api, 'server_remove_floating_ip') exception = novaclient_exceptions.ClientException('ClientException', message='clientException') api.server_remove_floating_ip(IsA(http.HttpRequest), IsA(int), IsA(int)).\ AndRaise(exception) self.mox.StubOutWithMock(messages, 'error') messages.error(IsA(http.HttpRequest), IsA(basestring)) self.mox.StubOutWithMock(api, 'tenant_floating_ip_get') api.tenant_floating_ip_get = self.mox.CreateMockAnything() api.tenant_floating_ip_get(IsA(http.HttpRequest), IsA(unicode)).\ AndReturn(self.floating_ip) self.mox.ReplayAll() res = self.client.post(reverse('dash_floating_ips_disassociate', args=[self.TEST_TENANT, 1]), {'floating_ip_id': self.floating_ip.id, 'method': 'FloatingIpDisassociate'}) self.assertRaises(novaclient_exceptions.ClientException) self.assertRedirects(res, reverse('dash_floating_ips', args=[self.TEST_TENANT])) self.mox.VerifyAll()
def test_associate_post(self): server = self.server self.mox.StubOutWithMock(api, 'server_list') api.server_list = self.mox.CreateMockAnything() api.server_list(IsA(http.HttpRequest)).AndReturn(self.servers) self.mox.StubOutWithMock(api, 'tenant_floating_ip_list') api.tenant_floating_ip_list(IsA(http.HttpRequest)).\ AndReturn(self.floating_ips) self.mox.StubOutWithMock(api, 'server_add_floating_ip') api.server_add_floating_ip = self.mox.CreateMockAnything() api.server_add_floating_ip(IsA(http.HttpRequest), IsA(unicode), IsA(unicode)).\ AndReturn(None) self.mox.StubOutWithMock(messages, 'info') messages.info(IsA(http.HttpRequest), IsA(unicode)) self.mox.StubOutWithMock(api, 'tenant_floating_ip_get') api.tenant_floating_ip_get = self.mox.CreateMockAnything() api.tenant_floating_ip_get(IsA(http.HttpRequest), str(1)).\ AndReturn(self.floating_ip) self.mox.ReplayAll() res = self.client.post(reverse('dash_floating_ips_associate', args=[self.TEST_TENANT, 1]), {'instance_id': 1, 'floating_ip_id': self.floating_ip.id, 'floating_ip': self.floating_ip.ip, 'method': 'FloatingIpAssociate'}) self.assertRedirects(res, reverse('dash_floating_ips', args=[self.TEST_TENANT])) self.mox.VerifyAll()
def test_disassociate_post_with_exception(self): self.mox.StubOutWithMock(api, 'tenant_floating_ip_list') api.tenant_floating_ip_list(IsA(http.HttpRequest)).\ AndReturn(self.floating_ips) self.mox.StubOutWithMock(api, 'server_remove_floating_ip') exception = novaclient_exceptions.ClientException( 'ClientException', message='clientException') api.server_remove_floating_ip(IsA(http.HttpRequest), IsA(int), IsA(int)).\ AndRaise(exception) self.mox.StubOutWithMock(messages, 'error') messages.error(IsA(http.HttpRequest), IsA(str)) self.mox.StubOutWithMock(api, 'tenant_floating_ip_get') api.tenant_floating_ip_get = self.mox.CreateMockAnything() api.tenant_floating_ip_get(IsA(http.HttpRequest), IsA(unicode)).\ AndReturn(self.floating_ip) self.mox.ReplayAll() res = self.client.post( reverse('dash_floating_ips_disassociate', args=[self.TEST_TENANT, 1]), { 'floating_ip_id': self.floating_ip.id, 'method': 'FloatingIpDisassociate' }) self.assertRaises(novaclient_exceptions.ClientException) self.assertRedirects( res, reverse('dash_floating_ips', args=[self.TEST_TENANT])) self.mox.VerifyAll()
def test_disassociate_post(self): self.mox.StubOutWithMock(api, 'tenant_floating_ip_list') api.tenant_floating_ip_list(IsA(http.HttpRequest)).\ AndReturn(self.floating_ips) self.mox.StubOutWithMock(api, 'server_remove_floating_ip') api.server_remove_floating_ip = self.mox.CreateMockAnything() api.server_remove_floating_ip(IsA(http.HttpRequest), IsA(int), IsA(int)).\ AndReturn(None) self.mox.StubOutWithMock(messages, 'info') messages.info(IsA(http.HttpRequest), IsA(unicode)) self.mox.StubOutWithMock(api, 'tenant_floating_ip_get') api.tenant_floating_ip_get = self.mox.CreateMockAnything() api.tenant_floating_ip_get(IsA(http.HttpRequest), IsA(unicode)).\ AndReturn(self.floating_ip) self.mox.ReplayAll() res = self.client.post( reverse('dash_floating_ips_disassociate', args=[self.TEST_TENANT, 1]), { 'floating_ip_id': self.floating_ip.id, 'method': 'FloatingIpDisassociate' }) self.assertRedirects( res, reverse('dash_floating_ips', args=[self.TEST_TENANT])) self.mox.VerifyAll()
def test_index(self): self.mox.StubOutWithMock(api, 'tenant_floating_ip_list') api.tenant_floating_ip_list(IsA(http.HttpRequest)).\ AndReturn(self.floating_ips) self.mox.ReplayAll() res = self.client.get(reverse('dash_floating_ips', args=[self.TEST_TENANT])) self.assertTemplateUsed(res, 'django_openstack/dash/floating_ips/index.html') self.assertItemsEqual(res.context['floating_ips'], self.floating_ips) self.mox.VerifyAll()
def test_index(self): self.mox.StubOutWithMock(api, 'tenant_floating_ip_list') api.tenant_floating_ip_list(IsA(http.HttpRequest)).\ AndReturn(self.floating_ips) self.mox.ReplayAll() res = self.client.get( reverse('dash_floating_ips', args=[self.TEST_TENANT])) self.assertTemplateUsed( res, 'django_openstack/dash/floating_ips/index.html') self.assertItemsEqual(res.context['floating_ips'], self.floating_ips) self.mox.VerifyAll()
def index(request, tenant_id): for f in (ReleaseFloatingIp, FloatingIpDisassociate, FloatingIpAllocate): _unused, handled = f.maybe_handle(request) if handled: return handled try: floating_ips = api.tenant_floating_ip_list(request) except novaclient_exceptions.ClientException, e: floating_ips = [] LOG.error("ClientException in floating ip index", exc_info=True) messages.error(request, 'Error fetching floating ips: %s' % e.message)
def index(request, tenant_id): for f in (ReleaseFloatingIp, FloatingIpDisassociate, FloatingIpAllocate): _unused, handled = f.maybe_handle(request) if handled: return handled try: floating_ips = api.tenant_floating_ip_list(request) except novaclient_exceptions.ClientException, e: floating_ips = [] LOG.exception("ClientException in floating ip index") messages.error(request, _("Error fetching floating ips: %s") % e.message)
def test_tenant_floating_ip_list(self): novaclient = self.stub_novaclient() novaclient.floating_ips = self.mox.CreateMockAnything() novaclient.floating_ips.list().AndReturn(self.floating_ips) self.mox.ReplayAll() floating_ips = api.tenant_floating_ip_list(self.request) self.assertEqual(len(floating_ips), len(self.floating_ips)) self.assertIsInstance(floating_ips[0], api.FloatingIp) self.mox.VerifyAll()