Skip to content

Commit

Permalink
change log level and add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mchugh19 committed Apr 4, 2019
1 parent 87b6843 commit 408942d
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 5 deletions.
10 changes: 5 additions & 5 deletions salt/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -2136,33 +2136,33 @@ def format_slots(self, cdata):
for key, value in arg.items():
try:
if value.startswith(SLOT_TEXT):
log.debug("Slot processsing dict value %s", value)
log.trace("Slot processsing dict value %s", value)
cdata[atype][ind][key] = self.__eval_slot(value)
except AttributeError:
# Not a string/slot
continue
elif isinstance(arg, list):
for idx, listvalue in enumerate(arg):
log.debug("Slot processing list value: %s", listvalue)
log.trace("Slot processing list value: %s", listvalue)
if isinstance(listvalue, dict):
# Search dict values in list for __slot__:
for key, value in listvalue.items():
try:
if value.startswith(SLOT_TEXT):
log.debug("Slot processsing nested dict value %s", value)
log.trace("Slot processsing nested dict value %s", value)
cdata[atype][ind][idx][key] = self.__eval_slot(value)
except AttributeError:
# Not a string/slot
continue
if isinstance(listvalue, six.text_type):
# Search strings in a list for __slot__:
if listvalue.startswith(SLOT_TEXT):
log.debug("Slot processsing nested string %s", listvalue)
log.trace("Slot processsing nested string %s", listvalue)
cdata[atype][ind][idx] = self.__eval_slot(listvalue)
elif isinstance(arg, six.text_type) \
and arg.startswith(SLOT_TEXT):
# Search strings for __slot__:
log.debug("Slot processsing %s", arg)
log.trace("Slot processsing %s", arg)
cdata[atype][ind] = self.__eval_slot(arg)
else:
# Not a slot, skip it
Expand Down
54 changes: 54 additions & 0 deletions tests/unit/test_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,60 @@ def test_format_slots_arg(self):
mock.assert_called_once_with('fun_arg', fun_key='fun_val')
self.assertEqual(cdata, {'args': ['fun_return'], 'kwargs': {'key': 'val'}})

def test_format_slots_dict_arg(self):
'''
Test the format slots is calling a slot specified in dict arg.
'''
cdata = {
'args': [
{'subarg': '__slot__:salt:mod.fun(fun_arg, fun_key=fun_val)'},
],
'kwargs': {
'key': 'val',
}
}
mock = MagicMock(return_value='fun_return')
with patch.dict(self.state_obj.functions, {'mod.fun': mock}):
self.state_obj.format_slots(cdata)
mock.assert_called_once_with('fun_arg', fun_key='fun_val')
self.assertEqual(cdata, {'args': [{'subarg': 'fun_return'}], 'kwargs': {'key': 'val'}})

def test_format_slots_listdict_arg(self):
'''
Test the format slots is calling a slot specified in list containing a dict.
'''
cdata = {
'args': [[
{'subarg': '__slot__:salt:mod.fun(fun_arg, fun_key=fun_val)'},
]],
'kwargs': {
'key': 'val',
}
}
mock = MagicMock(return_value='fun_return')
with patch.dict(self.state_obj.functions, {'mod.fun': mock}):
self.state_obj.format_slots(cdata)
mock.assert_called_once_with('fun_arg', fun_key='fun_val')
self.assertEqual(cdata, {'args': [[{'subarg': 'fun_return'}]], 'kwargs': {'key': 'val'}})

def test_format_slots_liststr_arg(self):
'''
Test the format slots is calling a slot specified in list containing a dict.
'''
cdata = {
'args': [[
'__slot__:salt:mod.fun(fun_arg, fun_key=fun_val)',
]],
'kwargs': {
'key': 'val',
}
}
mock = MagicMock(return_value='fun_return')
with patch.dict(self.state_obj.functions, {'mod.fun': mock}):
self.state_obj.format_slots(cdata)
mock.assert_called_once_with('fun_arg', fun_key='fun_val')
self.assertEqual(cdata, {'args': [['fun_return']], 'kwargs': {'key': 'val'}})

def test_format_slots_kwarg(self):
'''
Test the format slots is calling a slot specified in kwargs with corresponding arguments.
Expand Down

0 comments on commit 408942d

Please sign in to comment.