Skip to content

Commit

Permalink
unit_tests: fix winrm listener asserts
Browse files Browse the repository at this point in the history
mock.Mock().method_name.return_value if not set specifically, it returns
a mock, thus being equivalent to a logical True.

Added a return value in either case, so that it is visible.
Without the return value set in both cases, the unit test fail on Python
3.12.

Also, the try-`finally` is run outside of the `with` context, thus
moving the `assert_has_calls` after `with` checks.

Change-Id: Ic33afb6d1403b1096e06406ffd6d36a969f823d3
Signed-off-by: Adrian Vladu <[email protected]>
  • Loading branch information
ader1990 committed May 30, 2024
1 parent b241de1 commit 6c1dc5b
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions cloudbaseinit/tests/plugins/windows/test_winrmlistener.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,23 +102,22 @@ def _test_check_uac_remote_restrictions(self, mock_SecurityUtils,
mock_SecurityUtils.return_value = mock_security_utils
mock_osutils = mock.Mock()
mock_osutils.check_os_version.side_effect = [True, False]
mock_security_utils.get_uac_remote_restrictions.return_value = \
disable_uac_remote_restrictions
expected_set_token_calls = []
if disable_uac_remote_restrictions:
mock_security_utils.get_uac_remote_restrictions.return_value = \
disable_uac_remote_restrictions
expected_set_token_calls = [mock.call(enable=False),
mock.call(enable=True)]

with self._winrmlistener._check_uac_remote_restrictions(mock_osutils):
mock_SecurityUtils.assert_called_once_with()
mock_osutils.check_os_version.assert_has_calls(
[mock.call(6, 0), mock.call(6, 2)])
(mock_security_utils.get_uac_remote_restrictions.
assert_called_once_with())
if disable_uac_remote_restrictions:
expected_set_token_calls = [mock.call(enable=True)]
else:
expected_set_token_calls = [mock.call(enable=False),
mock.call(enable=True)]
mock_security_utils.set_uac_remote_restrictions.has_calls(
expected_set_token_calls)

mock_security_utils.set_uac_remote_restrictions.assert_has_calls(
expected_set_token_calls)

def test_check_uac_remote_restrictions(self):
self._test_check_uac_remote_restrictions(
Expand Down

0 comments on commit 6c1dc5b

Please sign in to comment.