From 3b50a7b98dc387c3efc71d325abe1f1fc33bbf2d Mon Sep 17 00:00:00 2001 From: Moe Date: Mon, 16 May 2016 07:31:19 -0700 Subject: [PATCH] Fix list_values, add test (#33264) --- salt/modules/reg.py | 3 ++- tests/unit/modules/reg_win_test.py | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/salt/modules/reg.py b/salt/modules/reg.py index 70bcb32656..0396af0f8a 100644 --- a/salt/modules/reg.py +++ b/salt/modules/reg.py @@ -285,8 +285,9 @@ def list_values(hive, key=None, use_32bit_registry=False, include_default=True): registry = Registry() hkey = registry.hkeys[local_hive] access_mask = registry.registry_32[use_32bit_registry] - + handle = None values = list() + try: handle = _winreg.OpenKey(hkey, local_key, 0, access_mask) diff --git a/tests/unit/modules/reg_win_test.py b/tests/unit/modules/reg_win_test.py index eba2cdcd12..9b958c55be 100644 --- a/tests/unit/modules/reg_win_test.py +++ b/tests/unit/modules/reg_win_test.py @@ -119,6 +119,27 @@ class RegWinTestCase(TestCase): test = len(test_list) > 5 # Their should be a lot more than 5 items self.assertTrue(test) + @skipIf(not sys.platform.startswith("win"), "requires Windows OS") + def test_list_values_fail(self): + ''' + Test - List the values under a subkey which does not exist. + ''' + subkey = 'ThisIsJunkItDoesNotExistIhope' + test_list = win_mod_reg.list_values('HKEY_LOCAL_MACHINE', subkey) + # returns a tuple with first item false, and second item a reason + test = isinstance(test_list, tuple) and (not test_list[0]) + self.assertTrue(test) + + @skipIf(not sys.platform.startswith("win"), "requires Windows OS") + def test_list_values(self): + ''' + Test - List the values under a subkey. + ''' + subkey = r'Software\Microsoft\Windows NT\CurrentVersion' + test_list = win_mod_reg.list_values('HKEY_LOCAL_MACHINE', subkey) + test = len(test_list) > 5 # There should be a lot more than 5 items + self.assertTrue(test) + # Not considering this destructive as its writing to a private space @skipIf(not sys.platform.startswith("win"), "requires Windows OS") def test_set_value_unicode(self):