Skip to content

Commit 6c1dc5b

Browse files
committed
unit_tests: fix winrm listener asserts
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 <avladu@cloudbasesolutions.com>
1 parent b241de1 commit 6c1dc5b

1 file changed

Lines changed: 8 additions & 9 deletions

File tree

cloudbaseinit/tests/plugins/windows/test_winrmlistener.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -102,23 +102,22 @@ def _test_check_uac_remote_restrictions(self, mock_SecurityUtils,
102102
mock_SecurityUtils.return_value = mock_security_utils
103103
mock_osutils = mock.Mock()
104104
mock_osutils.check_os_version.side_effect = [True, False]
105+
mock_security_utils.get_uac_remote_restrictions.return_value = \
106+
disable_uac_remote_restrictions
107+
expected_set_token_calls = []
105108
if disable_uac_remote_restrictions:
106-
mock_security_utils.get_uac_remote_restrictions.return_value = \
107-
disable_uac_remote_restrictions
109+
expected_set_token_calls = [mock.call(enable=False),
110+
mock.call(enable=True)]
108111

109112
with self._winrmlistener._check_uac_remote_restrictions(mock_osutils):
110113
mock_SecurityUtils.assert_called_once_with()
111114
mock_osutils.check_os_version.assert_has_calls(
112115
[mock.call(6, 0), mock.call(6, 2)])
113116
(mock_security_utils.get_uac_remote_restrictions.
114117
assert_called_once_with())
115-
if disable_uac_remote_restrictions:
116-
expected_set_token_calls = [mock.call(enable=True)]
117-
else:
118-
expected_set_token_calls = [mock.call(enable=False),
119-
mock.call(enable=True)]
120-
mock_security_utils.set_uac_remote_restrictions.has_calls(
121-
expected_set_token_calls)
118+
119+
mock_security_utils.set_uac_remote_restrictions.assert_has_calls(
120+
expected_set_token_calls)
122121

123122
def test_check_uac_remote_restrictions(self):
124123
self._test_check_uac_remote_restrictions(

0 commit comments

Comments
 (0)