From e206ba6a4cb136dad2574ce1ffc475c0f7d9c60b Mon Sep 17 00:00:00 2001 From: John Postlethwait Date: Sun, 11 Mar 2012 19:54:57 -0700 Subject: [PATCH] Ensuring the exception handler for the image detail page works. Change-Id: Ia39f1c48f89a0798e832f267dd35103c77f707c7 --- .../nova/images_and_snapshots/images/tests.py | 22 ++++++++++++++++--- .../nova/images_and_snapshots/images/views.py | 4 +--- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/horizon/dashboards/nova/images_and_snapshots/images/tests.py b/horizon/dashboards/nova/images_and_snapshots/images/tests.py index 49c39d415..aeae615a8 100644 --- a/horizon/dashboards/nova/images_and_snapshots/images/tests.py +++ b/horizon/dashboards/nova/images_and_snapshots/images/tests.py @@ -20,12 +20,16 @@ from django import http from django.core.urlresolvers import reverse -from keystoneclient import exceptions as keystone_exceptions -from mox import IgnoreArg, IsA + +from glance.common import exception as glance_exception from horizon import api from horizon import test +from keystoneclient import exceptions as keystone_exceptions + +from mox import IgnoreArg, IsA + IMAGES_INDEX_URL = reverse('horizon:nova:images_and_snapshots:index') @@ -219,8 +223,20 @@ class ImageViewTests(test.TestCase): self.mox.ReplayAll() res = self.client.get( - reverse('horizon:nova:images_and_snapshots:images:detail', + reverse('horizon:nova:images_and_snapshots:images:detail', args=[image.id])) self.assertTemplateUsed(res, 'nova/images_and_snapshots/images/detail.html') self.assertEqual(res.context['image'].name, image.name) + + def test_image_detail_get_with_exception(self): + image = self.images.first() + self.mox.StubOutWithMock(api.glance, 'image_get_meta') + api.glance.image_get_meta(IsA(http.HttpRequest), str(image.id)) \ + .AndRaise(glance_exception.NotFound) + self.mox.ReplayAll() + + res = self.client.get( + reverse('horizon:nova:images_and_snapshots:images:detail', + args=[image.id])) + self.assertRedirectsNoFollow(res, IMAGES_INDEX_URL) diff --git a/horizon/dashboards/nova/images_and_snapshots/images/views.py b/horizon/dashboards/nova/images_and_snapshots/images/views.py index e3ccaab86..a7d958f0d 100644 --- a/horizon/dashboards/nova/images_and_snapshots/images/views.py +++ b/horizon/dashboards/nova/images_and_snapshots/images/views.py @@ -23,8 +23,6 @@ Views for managing Nova images. """ import logging - -from django import shortcuts from django.core.urlresolvers import reverse from django.utils.translation import ugettext as _ @@ -180,8 +178,8 @@ class DetailView(views.APIView): try: image = api.glance.image_get_meta(self.request, kwargs['image_id']) except: + redirect = reverse('horizon:nova:images_and_snapshots:index') exceptions.handle(request, _('Unable to retrieve details for ' 'instance "%s".') % image_id, redirect=redirect) - shortcuts.redirect('horizon:nova:images_and_snapshots:index') return {'image': image}