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
This commit is contained in:
Itxaka 2017-07-05 15:45:01 +02:00
parent 3e9881ea5d
commit 70f074e7cb
No known key found for this signature in database
GPG Key ID: 0FFB0E56C3539E24
2 changed files with 4 additions and 3 deletions

View File

@ -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)

View File

@ -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))