Add unit test for format_log change

This commit is contained in:
rallytime 2016-06-02 09:26:39 -04:00
parent e68097445c
commit a580d1c6e0
2 changed files with 47 additions and 0 deletions

View file

@ -233,6 +233,8 @@ def format_log(ret):
new = chg[pkg]['new']
if not new and new not in (False, None):
new = 'absent'
# This must be able to handle unicode as some package names contain
# non-ascii characters like "Français" or "Español". See Issue #33605.
msg += u'\'{0}\' changed from \'{1}\' to \'{2}\'\n'.format(pkg, old, new)
if not msg:
msg = str(ret['changes'])

45
tests/unit/state_test.py Normal file
View file

@ -0,0 +1,45 @@
# -*- coding: utf-8 -*-
'''
:codeauthor: :email:`Nicole Thomas <nicole@saltstack.com>`
'''
# Import Python libs
from __future__ import absolute_import
# Import Salt Testing libs
from salttesting import TestCase, skipIf
from salttesting.helpers import ensure_in_syspath
from salttesting.mock import (
NO_MOCK,
NO_MOCK_REASON,
)
ensure_in_syspath('../')
# Import Salt libs
from salt import state
@skipIf(NO_MOCK, NO_MOCK_REASON)
class StateCompilerTestCase(TestCase):
'''
TestCase for the state compiler.
'''
def test_format_log_non_ascii_character(self):
'''
Tests running a non-ascii character through the state.format_log
function. See Issue #33605.
'''
# There is no return to test against as the format_log
# function doesn't return anything. However, we do want
# to make sure that the function doesn't stacktrace when
# called.
ret = {'changes': {'Français': {'old': 'something old',
'new': 'something new'}}}
state.format_log(ret)
if __name__ == '__main__':
from integration import run_tests
run_tests(StateCompilerTestCase, needs_daemon=False)