summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2016-03-03 19:39:59 +0000
committerGerrit Code Review <review@openstack.org>2016-03-03 19:39:59 +0000
commit66ea48a69f67c32601d398b657936846c147ea4d (patch)
tree798337ea63b8b9c5e1d78829dedafc313ffb7c1a
parent46c71761196c3dff4261d9ef085ad7bacc9c17c0 (diff)
parent9749d873a6243a8cf000f6eae58d5d2c2ed43106 (diff)
Merge "Fixing timezone awareness"9.0.0.0b3
-rw-r--r--horizon/middleware.py5
-rw-r--r--horizon/test/tests/middleware.py26
2 files changed, 31 insertions, 0 deletions
diff --git a/horizon/middleware.py b/horizon/middleware.py
index 4102419..f0ba394 100644
--- a/horizon/middleware.py
+++ b/horizon/middleware.py
@@ -29,6 +29,7 @@ from django.contrib import messages as django_messages
29from django import http 29from django import http
30from django import shortcuts 30from django import shortcuts
31from django.utils.encoding import iri_to_uri # noqa 31from django.utils.encoding import iri_to_uri # noqa
32from django.utils import timezone
32from django.utils.translation import ugettext_lazy as _ 33from django.utils.translation import ugettext_lazy as _
33 34
34from openstack_auth import views as auth_views 35from openstack_auth import views as auth_views
@@ -106,6 +107,10 @@ class HorizonMiddleware(object):
106 } 107 }
107 ) 108 )
108 109
110 tz = request.session.get('django_timezone')
111 if tz:
112 timezone.activate(tz)
113
109 def process_exception(self, request, exception): 114 def process_exception(self, request, exception):
110 """Catches internal Horizon exception classes such as NotAuthorized, 115 """Catches internal Horizon exception classes such as NotAuthorized,
111 NotFound and Http302 and handles them gracefully. 116 NotFound and Http302 and handles them gracefully.
diff --git a/horizon/test/tests/middleware.py b/horizon/test/tests/middleware.py
index 4b80b9a..694824b 100644
--- a/horizon/test/tests/middleware.py
+++ b/horizon/test/tests/middleware.py
@@ -16,6 +16,7 @@
16from django.conf import settings 16from django.conf import settings
17 17
18from django.http import HttpResponseRedirect # noqa 18from django.http import HttpResponseRedirect # noqa
19from django.utils import timezone
19 20
20from horizon import exceptions 21from horizon import exceptions
21from horizon import middleware 22from horizon import middleware
@@ -23,6 +24,15 @@ from horizon.test import helpers as test
23 24
24 25
25class MiddlewareTests(test.TestCase): 26class MiddlewareTests(test.TestCase):
27
28 def setUp(self):
29 self._timezone_backup = timezone.get_current_timezone_name()
30 return super(MiddlewareTests, self).setUp()
31
32 def tearDown(self):
33 timezone.activate(self._timezone_backup)
34 return super(MiddlewareTests, self).tearDown()
35
26 def test_redirect_login_fail_to_login(self): 36 def test_redirect_login_fail_to_login(self):
27 url = settings.LOGIN_URL 37 url = settings.LOGIN_URL
28 request = self.factory.post(url) 38 request = self.factory.post(url)
@@ -49,3 +59,19 @@ class MiddlewareTests(test.TestCase):
49 resp = mw.process_response(request, response) 59 resp = mw.process_response(request, response)
50 self.assertEqual(200, resp.status_code) 60 self.assertEqual(200, resp.status_code)
51 self.assertEqual(url, resp['X-Horizon-Location']) 61 self.assertEqual(url, resp['X-Horizon-Location'])
62
63 def test_timezone_awareness(self):
64 url = settings.LOGIN_REDIRECT_URL
65 mw = middleware.HorizonMiddleware()
66
67 request = self.factory.get(url)
68 request.session['django_timezone'] = 'America/Chicago'
69 mw.process_request(request)
70 self.assertEqual(
71 timezone.get_current_timezone_name(), 'America/Chicago')
72 request.session['django_timezone'] = 'Europe/Paris'
73 mw.process_request(request)
74 self.assertEqual(timezone.get_current_timezone_name(), 'Europe/Paris')
75 request.session['django_timezone'] = 'UTC'
76 mw.process_request(request)
77 self.assertEqual(timezone.get_current_timezone_name(), 'UTC')