<s> import importlib <EOL> import unittest <EOL> try : <EOL> import unittest . mock as mock <EOL> except ImportError : <EOL> import mock <EOL> class FakeWindowsError ( Exception ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , errno ) : <EOL> self . errno = errno <EOL> class WindowsSecurityUtilsTests ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . _moves_mock = mock . MagicMock ( ) <EOL> self . _module_patcher = mock . patch . dict ( <EOL> '<STR_LIT>' , <EOL> { '<STR_LIT>' : self . _moves_mock } ) <EOL> self . _module_patcher . start ( ) <EOL> self . _winreg_mock = self . _moves_mock . winreg <EOL> self . security = importlib . import_module ( <EOL> "<STR_LIT>" ) <EOL> self . security . WindowsError = FakeWindowsError <EOL> self . _security_utils = self . security . WindowsSecurityUtils ( ) <EOL> def tearDown ( self ) : <EOL> self . _module_patcher . stop ( ) <EOL> def test_set_uac_remote_restrictions ( self ) : <EOL> fake_value = False <EOL> self . _security_utils . set_uac_remote_restrictions ( <EOL> enable = fake_value ) <EOL> self . _winreg_mock . SetValueEx . assert_called_once_with ( <EOL> self . _winreg_mock . CreateKey . return_value . __enter__ ( ) , <EOL> self . _security_utils . _LATFP_VALUE_NAME , <NUM_LIT:0> , <EOL> self . _winreg_mock . REG_DWORD , not fake_value ) <EOL> self . _winreg_mock . CreateKey . assert_called_once_with ( <EOL> self . _winreg_mock . HKEY_LOCAL_MACHINE , <EOL> self . _security_utils . _SYSTEM_POLICIES_KEY ) <EOL> def _test_get_uac_remote_restrictions_win_error ( self , ret_error = False ) : <EOL> fake_errno = <NUM_LIT:2> <EOL> if ret_error : <EOL> fake_errno = <NUM_LIT:0> <EOL> self . _winreg_mock . OpenKey . side_effect = [ <EOL> self . security . WindowsError ( fake_errno ) ] <EOL> if ret_error : <EOL> self . assertRaises ( self . security . WindowsError , <EOL> self . _security_utils . get_uac_remote_restrictions ) <EOL> else : <EOL> response = self . _security_utils . get_uac_remote_restrictions ( ) <EOL> self . assertTrue ( response ) <EOL> def test_get_uac_remote_restrictions_win_error_ret_error ( self ) : <EOL> self . _test_get_uac_remote_restrictions_win_error ( ret_error = True ) <EOL> def test_get_uac_remote_restrictions_win_error ( self ) : <EOL> self . _test_get_uac_remote_restrictions_win_error ( ret_error = False ) <EOL> def test_get_uac_remote_restrictions_no_error ( self ) : <EOL> key = mock . MagicMock ( ) <EOL> fake_key_value = <NUM_LIT:0> <EOL> key . __enter__ . return_value = fake_key_value <EOL> fake_reg_type = mock . sentinel . fake_reg_type <EOL> self . _winreg_mock . OpenKey . return_value = key <EOL> self . _winreg_mock . QueryValueEx . return_value = ( fake_key_value , <EOL> fake_reg_type ) <EOL> response = self . _security_utils . get_uac_remote_restrictions ( ) <EOL> self . _winreg_mock . QueryValueEx . assert_called_once_with ( <EOL> fake_key_value , <EOL> self . _security_utils . _LATFP_VALUE_NAME ) <EOL> self . _winreg_mock . OpenKey . assert_called_once_with ( <EOL> self . _winreg_mock . HKEY_LOCAL_MACHINE , <EOL> self . _security_utils . _SYSTEM_POLICIES_KEY ) <EOL> self . assertTrue ( bool ( response ) ) </s>
