Skip to content
This repository has been archived by the owner on Jun 5, 2023. It is now read-only.

[Issue 1848] Mock out logger to fix pollution of test logs. #1899

Merged
merged 1 commit into from
Aug 17, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 9 additions & 3 deletions tests/enforcer/gce_firewall_enforcer_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1168,7 +1168,8 @@ def test_apply_change_no_rules(self):
self.assertListEqual([], failures)
self.assertListEqual([], change_errors)

def test_apply_change_insert_http_error(self):
@mock.patch('google.cloud.forseti.enforcer.gce_firewall_enforcer.LOGGER', autospec=True)
def test_apply_change_insert_http_error(self, mock_logger):
"""Adds the rule to failures on HttpError exception.

Setup:
Expand Down Expand Up @@ -1201,8 +1202,10 @@ def test_apply_change_insert_http_error(self):
test_rules[0].get('name', ''),
error_409)
self.assertListEqual([error_str], change_errors)
self.assertTrue(mock_logger.exception.called)

def test_apply_change_operation_status_error(self):
@mock.patch('google.cloud.forseti.enforcer.gce_firewall_enforcer.LOGGER', autospec=True)
def test_apply_change_operation_status_error(self, mock_logger):
"""Adds the rule to failures on HttpError exception.

Setup:
Expand Down Expand Up @@ -1236,6 +1239,7 @@ def test_apply_change_operation_status_error(self):
self.assertSameStructure(test_rules, failures)
self.assertListEqual([], successes)
self.assertListEqual([], change_errors)
self.assertTrue(mock_logger.error.called)

def test_apply_change_lots_of_rules(self):
"""Changing more rules than permitted by the operation semaphore works.
Expand Down Expand Up @@ -1303,7 +1307,8 @@ def test_apply_changes(self):
[constants.EXPECTED_FIREWALL_RULES['test-network-allow-public-0']],
self.enforcer.get_updated_rules())

def test_apply_changes_operation_status_error(self):
@mock.patch('google.cloud.forseti.enforcer.gce_firewall_enforcer.LOGGER', autospec=True)
def test_apply_changes_operation_status_error(self, mock_logger):
"""Validate that an error on a change raises the expected exception.

Setup:
Expand Down Expand Up @@ -1352,6 +1357,7 @@ def test_apply_changes_operation_status_error(self):
self.enforcer._apply_change_set(delete_before_insert)
self.assertEqual([], self.enforcer.get_updated_rules())
self.enforcer._rules_to_update = []
self.assertTrue(mock_logger.error.called)

def testApplyChangesDeleteFirst(self):
"""Validate _ApplyChanges works with no errors.
Expand Down