Merge "Clarify middleware public methods"

This commit is contained in:
Zuul 2018-11-21 22:01:58 +00:00 committed by Gerrit Code Review
commit 25d72fa5c5
5 changed files with 16 additions and 16 deletions

View File

@ -47,12 +47,12 @@ class HorizonMiddleware(object):
self.get_response = get_response
def __call__(self, request):
self.process_request(request)
self._process_request(request)
response = self.get_response(request)
response = self.process_response(request, response)
response = self._process_response(request, response)
return response
def process_request(self, request):
def _process_request(self, request):
"""Adds data necessary for Horizon to function to the request."""
request.horizon = {'dashboard': None,
@ -147,11 +147,11 @@ class HorizonMiddleware(object):
return shortcuts.redirect(exception.location)
@staticmethod
def copy_headers(src, dst, headers):
def _copy_headers(src, dst, headers):
for header in headers:
dst[header] = src[header]
def process_response(self, request, response):
def _process_response(self, request, response):
"""Convert HttpResponseRedirect to HttpResponse if request is via ajax.
This is to allow ajax request to redirect url.
@ -189,8 +189,8 @@ class HorizonMiddleware(object):
redirect_response['X-Horizon-Location'] = response['location']
upload_url_key = 'X-File-Upload-URL'
if upload_url_key in response:
self.copy_headers(response, redirect_response,
(upload_url_key, 'X-Auth-Token'))
self._copy_headers(response, redirect_response,
(upload_url_key, 'X-Auth-Token'))
return redirect_response
if queued_msgs:
# TODO(gabriel): When we have an async connection to the

View File

@ -81,10 +81,10 @@ class OperationLogMiddleware(object):
def __call__(self, request):
response = self.get_response(request)
response = self.process_response(request, response)
response = self._process_response(request, response)
return response
def process_response(self, request, response):
def _process_response(self, request, response):
"""Log user operation."""
log_format = self._get_log_format(request)
if not log_format:

View File

@ -133,7 +133,7 @@ class TestCase(django_test.TestCase):
# A dummy get_response function (which is not callable) is passed
# because middlewares below are used only to populate request attrs.
middleware.HorizonMiddleware('dummy_get_response') \
.process_request(self.request)
._process_request(self.request)
AuthenticationMiddleware('dummy_get_response') \
.process_request(self.request)
os.environ["HORIZON_TEST_RUN"] = "True"

View File

@ -61,7 +61,7 @@ class MiddlewareTests(django_test.TestCase):
response = HttpResponseRedirect(url)
response.client = self.client
resp = mw.process_response(request, response)
resp = mw._process_response(request, response)
self.assertEqual(200, resp.status_code)
self.assertEqual(url, resp['X-Horizon-Location'])
@ -71,12 +71,12 @@ class MiddlewareTests(django_test.TestCase):
request = self.factory.get(url)
request.session['django_timezone'] = 'America/Chicago'
mw.process_request(request)
mw._process_request(request)
self.assertEqual(
timezone.get_current_timezone_name(), 'America/Chicago')
request.session['django_timezone'] = 'Europe/Paris'
mw.process_request(request)
mw._process_request(request)
self.assertEqual(timezone.get_current_timezone_name(), 'Europe/Paris')
request.session['django_timezone'] = 'UTC'
mw.process_request(request)
mw._process_request(request)
self.assertEqual(timezone.get_current_timezone_name(), 'UTC')

View File

@ -35,7 +35,7 @@ class MessageTests(test.TestCase):
self.assertItemsEqual(req.horizon['async_messages'], [expected])
res = http.HttpResponse()
res = middleware.HorizonMiddleware('dummy_get_response') \
.process_response(req, res)
._process_response(req, res)
self.assertEqual(json.dumps([expected]),
res['X-Horizon-Messages'])
@ -50,6 +50,6 @@ class MessageTests(test.TestCase):
self.assertItemsEqual(req.horizon['async_messages'], [expected])
res = http.HttpResponse()
res = middleware.HorizonMiddleware('dummy_get_response') \
.process_response(req, res)
._process_response(req, res)
self.assertEqual(json.dumps([expected]),
res['X-Horizon-Messages'])