From 70f074e7cb88ed7adfaff681594947ca0ef57452 Mon Sep 17 00:00:00 2001 From: Itxaka Date: Wed, 5 Jul 2017 15:45:01 +0200 Subject: [PATCH] Fix operation_log middleware tests There seems to be a couple of errors on the operation_log middleware tests that were being ignored on the tests runnners. On the first we were trying to access a local var from the OperationLogMiddleware class to compare the default log format. This is fixed by making it an attribute instead. The second one was an icorrect use of the delattr function as it was used as part of the request object, while its a standalone function. Change-Id: Ib05cfd1d6acb940a40c8bb1d1bdf3cdf837a0454 --- horizon/middleware/operation_log.py | 4 ++-- horizon/test/tests/middleware.py | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/horizon/middleware/operation_log.py b/horizon/middleware/operation_log.py index bafcce4185..973ed66947 100644 --- a/horizon/middleware/operation_log.py +++ b/horizon/middleware/operation_log.py @@ -60,7 +60,7 @@ class OperationLogMiddleware(object): _log_option = getattr(settings, "OPERATION_LOG_OPTIONS", {}) _available_methods = ['POST', 'GET', 'PUT', 'DELETE'] _methods = _log_option.get("target_methods", ['POST']) - _default_format = ( + self._default_format = ( "[%(client_ip)s] [%(domain_name)s]" " [%(domain_id)s] [%(project_name)s]" " [%(project_id)s] [%(user_name)s] [%(user_id)s]" @@ -69,7 +69,7 @@ class OperationLogMiddleware(object): _default_ignored_urls = ['/js/', '/static/', '^/api/'] self.target_methods = [x for x in _methods if x in _available_methods] self.mask_fields = _log_option.get("mask_fields", ['password']) - self.format = _log_option.get("format", _default_format) + self.format = _log_option.get("format", self._default_format) self._logger = logging.getLogger('horizon.operation_log') ignored_urls = _log_option.get("ignore_urls", _default_ignored_urls) diff --git a/horizon/test/tests/middleware.py b/horizon/test/tests/middleware.py index c85a773474..81e4f86981 100644 --- a/horizon/test/tests/middleware.py +++ b/horizon/test/tests/middleware.py @@ -196,6 +196,7 @@ class OperationLogMiddlewareTest(test.TestCase): self.assertIn(data, logging_str) @override_settings(OPERATION_LOG_ENABLED=True) + @override_settings(OPERATION_LOG_OPTIONS={'target_methods': ['GET']}) @patch(('horizon.middleware.operation_log.OperationLogMiddleware.' 'OPERATION_LOG')) def test_get_log_format(self, mock_logger): @@ -210,7 +211,7 @@ class OperationLogMiddlewareTest(test.TestCase): def test_get_log_format_no_user(self, mock_logger): olm = middleware.OperationLogMiddleware() request, _ = self._test_ready_for_get() - request.delattr("user") + delattr(request, "user") self.assertIsNone(olm._get_log_format(request))