def test_index_no_images(self): self.mox.StubOutWithMock(api, 'snapshot_list_detailed') api.snapshot_list_detailed(IsA(http.HttpRequest)).\ AndReturn(self.snapshots) self.mox.StubOutWithMock(api, 'flavor_list') api.flavor_list(IsA(http.HttpRequest)).AndReturn(self.flavors) self.mox.StubOutWithMock(api, 'security_group_list') api.security_group_list(IsA(http.HttpRequest)).\ AndReturn(self.security_groups) self.mox.StubOutWithMock(api, 'keypair_list') api.keypair_list(IsA(http.HttpRequest)).AndReturn(self.keypairs) self.mox.StubOutWithMock(api, 'image_list_detailed') api.image_list_detailed(IsA(http.HttpRequest)).AndReturn([]) self.mox.StubOutWithMock(api, 'tenant_quota_get') api.tenant_quota_get(IsA(http.HttpRequest), self.TEST_TENANT) \ .AndReturn({}) self.mox.StubOutWithMock(messages, 'info') messages.info(IsA(http.HttpRequest), IsA(basestring)) self.mox.ReplayAll() res = self.client.get(INDEX_URL) self.assertTemplateUsed(res, 'engine/images_and_snapshots/index.html')
def test_index_client_conn_error(self): self.mox.StubOutWithMock(api, 'image_list_detailed') exception = tank_exception.ClientConnectionError('clientConnError') api.image_list_detailed(IsA(http.HttpRequest)).AndRaise(exception) self.mox.StubOutWithMock(api, 'tenant_quota_get') api.tenant_quota_get(IsA(http.HttpRequest), self.TEST_TENANT) \ .AndReturn({}) self.mox.StubOutWithMock(messages, 'error') messages.error(IsA(http.HttpRequest), IsA(basestring)) self.mox.ReplayAll() res = self.client.get(INDEX_URL) self.assertTemplateUsed(res, 'engine/images_and_snapshots/index.html')
def index(request): for f in (DeleteImage, ): unused, handled = f.maybe_handle(request) if handled: return handled all_images = [] try: all_images = api.image_list_detailed(request) if not all_images: messages.info(request, _("There are currently no images.")) except tank_exception.ClientConnectionError, e: LOG.exception("Error connecting to tank") messages.error(request, _("Error connecting to tank: %s") % str(e))
def test_index(self): self.mox.StubOutWithMock(api, 'image_list_detailed') api.image_list_detailed(IsA(http.HttpRequest)).AndReturn(self.images) self.mox.StubOutWithMock(api, 'snapshot_list_detailed') api.snapshot_list_detailed(IsA(http.HttpRequest)).AndReturn( self.snapshots) self.mox.StubOutWithMock(api, 'flavor_list') api.flavor_list(IsA(http.HttpRequest)).AndReturn(self.flavors) api.flavor_list(IsA(http.HttpRequest)).AndReturn(self.flavors) self.mox.StubOutWithMock(api, 'security_group_list') api.security_group_list(IsA(http.HttpRequest)).\ AndReturn(self.security_groups) api.security_group_list(IsA(http.HttpRequest)).\ AndReturn(self.security_groups) self.mox.StubOutWithMock(api, 'keypair_list') api.keypair_list(IsA(http.HttpRequest)).AndReturn(self.keypairs) self.mox.StubOutWithMock(api, 'tenant_quota_get') api.tenant_quota_get(IsA(http.HttpRequest), self.TEST_TENANT).AndReturn({}) self.mox.ReplayAll() res = self.client.get(INDEX_URL) self.assertTemplateUsed(res, 'engine/images_and_snapshots/index.html') self.assertIn('images', res.context) images = res.context['images'] self.assertEqual(len(images), 1) self.assertEqual(images[0].name, 'visibleImage')
def index(request): for f in (DeleteImage, ToggleImage): form, handled = f.maybe_handle(request) if handled: return handled # We don't have any way of showing errors for these, so don't bother # trying to reuse the forms from above delete_form = DeleteImage() toggle_form = ToggleImage() images = [] try: images = api.image_list_detailed(request) if not images: messages.info(request, _("There are currently no images.")) except tank_exception.ClientConnectionError, e: LOG.exception("Error connecting to tank") messages.error(request, _("Error connecting to tank: %s") % e.message)