'Test change_unrar_tool'

@mock.patch('platform.system', mock.MagicMock(return_value='Windows'))
@mock.patch('sickbeard.helpers.download_file', mock.MagicMock(return_value=True))
@mock.patch('sickbeard.helpers.extractZip', mock.MagicMock(return_value=True))
def test_change_unrar_tool(self):

    custom_check_mock = mock.patch('rarfile.custom_check', mock.MagicMock())
    custom_check_mock.new.side_effect = [RarExecError(), True]
    with custom_check_mock:
        with mock.patch('os.path.exists', mock.MagicMock(return_value=True)):
            with mock.patch('os.path.getsize', mock.MagicMock(return_value=447440)):
                with mock.patch('os.remove'):
                    self.assertTrue(config.change_unrar_tool('unrar', 'bsdtar'))
    my_environ = mock.patch.dict(os.environ, {'ProgramFiles': 'C:\\Program    Files    (x86)\\'}, clear=True)
    with my_environ:
        self.assertFalse(config.change_unrar_tool('unrar', 'bsdtar'))
    sickbeard.PROG_DIR = 'C:\\SickRage'
    my_environ = mock.patch.dict(os.environ, {'ProgramFiles': 'C:\\Program    Files    (x86)\\', 'ProgramFiles(x86)': 'C:\\Program    Files    (x86)\\', 'ProgramW6432': 'C:\\Program    Files\\'}, clear=True)
    custom_check_mock.new.side_effect = [RarExecError(), RarExecError(), True, True, True, True]
    isfile_mock = mock.patch('os.path.isfile', mock.MagicMock())
    isfile_mock.new.side_effect = [True, False, True]
    with custom_check_mock:
        with isfile_mock:
            with my_environ:
                self.assertTrue(config.change_unrar_tool('unrar', 'bsdtar'))
