Don't call a method that doesn't exist for unauth'd requests.

Fixes a broken method call in a previously untested code path.

Change-Id: I72343ba51f9871b4e85641d773b574fb218fb158
This commit is contained in:
Gabriel Hurley 2012-08-09 19:00:49 -07:00
parent 87ef0db150
commit c96677576a
3 changed files with 20 additions and 1 deletions

View File

@ -49,6 +49,20 @@ class UsageViewTests(test.TestCase):
self.assertTrue(isinstance(res.context['usage'], usage.TenantUsage)) self.assertTrue(isinstance(res.context['usage'], usage.TenantUsage))
self.assertContains(res, 'form-horizontal') self.assertContains(res, 'form-horizontal')
def test_unauthorized(self):
exc = self.exceptions.keystone_unauthorized
now = timezone.now()
self.mox.StubOutWithMock(api, 'usage_get')
api.usage_get(IsA(http.HttpRequest), self.tenant.id,
datetime.datetime(now.year, now.month, 1, 0, 0, 0),
Func(usage.almost_now)) \
.AndRaise(exc)
self.mox.ReplayAll()
url = reverse('horizon:nova:overview:index')
res = self.client.get(url)
self.assertRedirects(res, reverse("login") + "?next=" + url)
def test_usage_csv(self): def test_usage_csv(self):
now = timezone.now() now = timezone.now()
usage_obj = api.nova.Usage(self.usages.first()) usage_obj = api.nova.Usage(self.usages.first())

View File

@ -23,6 +23,7 @@ import os
import sys import sys
from django.conf import settings from django.conf import settings
from django.contrib.auth import logout
from django.http import HttpRequest from django.http import HttpRequest
from django.utils import termcolors from django.utils import termcolors
from django.utils.translation import ugettext as _ from django.utils.translation import ugettext as _
@ -260,7 +261,7 @@ def handle(request, message=None, redirect=None, ignore=False,
if issubclass(exc_type, UNAUTHORIZED): if issubclass(exc_type, UNAUTHORIZED):
if ignore: if ignore:
return NotAuthorized return NotAuthorized
request.user_logout() logout(request)
if not force_silence and not handled: if not force_silence and not handled:
log_method(error_color("Unauthorized: %s" % exc_value)) log_method(error_color("Unauthorized: %s" % exc_value))
if not handled: if not handled:

View File

@ -23,6 +23,10 @@ def data(TEST):
TEST.exceptions = TestDataContainer() TEST.exceptions = TestDataContainer()
msg = "Expected failure." msg = "Expected failure."
keystone_unauthorized = keystone_exceptions.Unauthorized(401)
keystone_unauthorized.silence_logging = True
TEST.exceptions.keystone_unauthorized = keystone_unauthorized
keystone_exception = keystone_exceptions.ClientException(500, message=msg) keystone_exception = keystone_exceptions.ClientException(500, message=msg)
keystone_exception.silence_logging = True keystone_exception.silence_logging = True
TEST.exceptions.keystone = keystone_exception TEST.exceptions.keystone = keystone_exception