diff options
author | Boris Bobrov <bbobrov@mirantis.com> | 2016-11-01 16:33:39 +0300 |
---|---|---|
committer | Boris Bobrov <bbobrov@mirantis.com> | 2016-11-01 16:33:39 +0300 |
commit | b736936e51df4043c5fddc094355584de831185c (patch) | |
tree | 1943f350ed254801ba5b863a761101cf2ade3940 | |
parent | 8a5762fbca7962fc81297b8633a78e7ae977456c (diff) | |
download | keystonemiddleware-b736936e51df4043c5fddc094355584de831185c.tar.gz |
Mock log only after app creation
The unit test that is getting fixed fails with error:
AttributeError: None does not have the attribute 'info'
It happens because _LOG.info is being patched at the moment when _LOG
is None. For a reason, this doesn't happen always. For example,
the problem was gone after a recheck in
https://review.openstack.org/#/c/391130/.
Patch log only after app creation. This seems to be a common pattern
across all other tests involving mock, for example, in
test_conf_middleware_log_and_default_as_messaging.
Change-Id: Ia48520d6835c5712d77e182cffbf50cc6b56b9ce
-rw-r--r-- | keystonemiddleware/tests/unit/audit/test_logging_notifier.py | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/keystonemiddleware/tests/unit/audit/test_logging_notifier.py b/keystonemiddleware/tests/unit/audit/test_logging_notifier.py index f0174ad..0801861 100644 --- a/keystonemiddleware/tests/unit/audit/test_logging_notifier.py +++ b/keystonemiddleware/tests/unit/audit/test_logging_notifier.py @@ -25,15 +25,16 @@ class TestLoggingNotifier(base.BaseAuditMiddlewareTest): super(TestLoggingNotifier, self).setUp() - @mock.patch('keystonemiddleware.audit._LOG.info') - def test_api_request_no_messaging(self, log): - self.create_simple_app().get('/foo/bar', - extra_environ=self.get_environ_header()) - - # Check first notification with only 'request' - call_args = log.call_args_list[0][0] - self.assertEqual('audit.http.request', call_args[1]['event_type']) - - # Check second notification with request + response - call_args = log.call_args_list[1][0] - self.assertEqual('audit.http.response', call_args[1]['event_type']) + def test_api_request_no_messaging(self): + app = self.create_simple_app() + + with mock.patch('keystonemiddleware.audit._LOG.info') as log: + app.get('/foo/bar', extra_environ=self.get_environ_header()) + + # Check first notification with only 'request' + call_args = log.call_args_list[0][0] + self.assertEqual('audit.http.request', call_args[1]['event_type']) + + # Check second notification with request + response + call_args = log.call_args_list[1][0] + self.assertEqual('audit.http.response', call_args[1]['event_type']) |