diff options
author | Andrew Butcher <abutcher@afrolegs.com> | 2016-10-21 13:39:12 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-10-21 13:39:12 -0400 |
commit | b5570b656e59756ad6ea5b24be253f15d0e3ca41 (patch) | |
tree | 2b8ab1e00a258f7e567b789820ff90daebfd1298 /utils/test/test_utils.py | |
parent | 65a478443e4c86576f99936dac3f2989c685552e (diff) | |
parent | 98baba232264c1434d76d4f5cb4ac6283a4f9a2c (diff) | |
download | openshift-b5570b656e59756ad6ea5b24be253f15d0e3ca41.tar.gz openshift-b5570b656e59756ad6ea5b24be253f15d0e3ca41.tar.bz2 openshift-b5570b656e59756ad6ea5b24be253f15d0e3ca41.tar.xz openshift-b5570b656e59756ad6ea5b24be253f15d0e3ca41.zip |
Merge pull request #2639 from tbielawa/test-utils-debugging
Unit tests for the debug_env logger thing
Diffstat (limited to 'utils/test/test_utils.py')
-rw-r--r-- | utils/test/test_utils.py | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/utils/test/test_utils.py b/utils/test/test_utils.py new file mode 100644 index 000000000..8d59f388e --- /dev/null +++ b/utils/test/test_utils.py @@ -0,0 +1,72 @@ +""" +Unittests for ooinstall utils. +""" + +import unittest +import logging +import sys +import copy +from ooinstall.utils import debug_env +import mock + + +class TestUtils(unittest.TestCase): + """ + Parent unittest TestCase. + """ + + def setUp(self): + self.debug_all_params = { + 'OPENSHIFT_FOO': 'bar', + 'ANSIBLE_FOO': 'bar', + 'OO_FOO': 'bar' + } + + self.expected = [ + mock.call('ANSIBLE_FOO: bar'), + mock.call('OPENSHIFT_FOO: bar'), + mock.call('OO_FOO: bar'), + ] + + # python 2.x has assertItemsEqual, python 3.x has assertCountEqual + if sys.version_info.major > 3: + self.assertItemsEqual = self.assertCountEqual + + ###################################################################### + # Validate ooinstall.utils.debug_env functionality + + def test_utils_debug_env_all_debugged(self): + """Verify debug_env debugs specific env variables""" + + with mock.patch('ooinstall.utils.installer_log') as _il: + debug_env(self.debug_all_params) + print _il.debug.call_args_list + + # Debug was called for each item we expect + self.assertEqual( + len(self.debug_all_params), + _il.debug.call_count) + + # Each item we expect was logged + self.assertItemsEqual( + self.expected, + _il.debug.call_args_list) + + def test_utils_debug_env_some_debugged(self): + """Verify debug_env skips non-wanted env variables""" + debug_some_params = copy.deepcopy(self.debug_all_params) + # This will not be logged by debug_env + debug_some_params['MG_FRBBR'] = "SKIPPED" + + with mock.patch('ooinstall.utils.installer_log') as _il: + debug_env(debug_some_params) + + # The actual number of debug calls was less than the + # number of items passed to debug_env + self.assertLess( + _il.debug.call_count, + len(debug_some_params)) + + self.assertItemsEqual( + self.expected, + _il.debug.call_args_list) |